1 /*
2 * Copyright (c) 2022-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 #include "js_text_input_client_engine.h"
17
18 #include "input_method_ability.h"
19 #include "js_utils.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "string_ex.h"
23
24 namespace OHOS {
25 namespace MiscServices {
26 thread_local napi_ref JsTextInputClientEngine::TICRef_ = nullptr;
27 const std::string JsTextInputClientEngine::TIC_CLASS_NAME = "TextInputClient";
28
Init(napi_env env,napi_value info)29 napi_value JsTextInputClientEngine::Init(napi_env env, napi_value info)
30 {
31 IMSA_HILOGI("JsTextInputClientEngine init");
32 napi_property_descriptor properties[] = {
33 DECLARE_NAPI_FUNCTION("sendKeyFunction", SendKeyFunction),
34 DECLARE_NAPI_FUNCTION("deleteForward", DeleteForward),
35 DECLARE_NAPI_FUNCTION("deleteBackward", DeleteBackward),
36 DECLARE_NAPI_FUNCTION("insertText", InsertText),
37 DECLARE_NAPI_FUNCTION("getForward", GetForward),
38 DECLARE_NAPI_FUNCTION("getBackward", GetBackward),
39 DECLARE_NAPI_FUNCTION("getEditorAttribute", GetEditorAttribute),
40 DECLARE_NAPI_FUNCTION("moveCursor", MoveCursor),
41 };
42 napi_value cons = nullptr;
43 NAPI_CALL(env, napi_define_class(env, TIC_CLASS_NAME.c_str(), TIC_CLASS_NAME.size(),
44 JsConstructor, nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &cons));
45 NAPI_CALL(env, napi_create_reference(env, cons, 1, &TICRef_));
46 NAPI_CALL(env, napi_set_named_property(env, info, TIC_CLASS_NAME.c_str(), cons));
47
48 return info;
49 }
50
MoveCursor(napi_env env,napi_callback_info info)51 napi_value JsTextInputClientEngine::MoveCursor(napi_env env, napi_callback_info info)
52 {
53 auto ctxt = std::make_shared<MoveCursorContext>();
54 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
55 napi_status status = napi_generic_failure;
56 napi_valuetype valueType = napi_undefined;
57 napi_typeof(env, argv[0], &valueType);
58 if (argc < 1) {
59 JsUtils::ThrowException(
60 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
61 return status;
62 }
63 if (valueType != napi_number) {
64 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " direction", TypeCode::TYPE_NUMBER);
65 return status;
66 }
67 status = GetMoveCursorParam(env, argv[0], ctxt);
68 return status;
69 };
70 auto exec = [ctxt](AsyncCall::Context *ctx) {
71 int32_t code = InputMethodAbility::GetInstance()->MoveCursor(ctxt->num);
72 if (code == ErrorCode::NO_ERROR) {
73 ctxt->status = napi_ok;
74 ctxt->SetState(ctxt->status);
75 } else {
76 ctxt->SetErrorCode(code);
77 }
78 };
79 ctxt->SetAction(std::move(input));
80 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt));
81 return asyncCall.Call(env, exec);
82 }
83
JsConstructor(napi_env env,napi_callback_info cbinfo)84 napi_value JsTextInputClientEngine::JsConstructor(napi_env env, napi_callback_info cbinfo)
85 {
86 napi_value thisVar = nullptr;
87 NAPI_CALL(env, napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, nullptr));
88
89 JsTextInputClientEngine *clientObject = new (std::nothrow) JsTextInputClientEngine();
90 if (clientObject == nullptr) {
91 IMSA_HILOGE("clientObject is nullptr");
92 napi_value result = nullptr;
93 napi_get_null(env, &result);
94 return result;
95 }
96 auto finalize = [](napi_env env, void *data, void *hint) {
97 IMSA_HILOGE("JsTextInputClientEngine finalize");
98 auto *objInfo = reinterpret_cast<JsTextInputClientEngine *>(data);
99 if (objInfo != nullptr) {
100 delete objInfo;
101 }
102 };
103 napi_status status = napi_wrap(env, thisVar, clientObject, finalize, nullptr, nullptr);
104 if (status != napi_ok) {
105 IMSA_HILOGE("JsTextInputClientEngine napi_wrap failed: %{public}d", status);
106 delete clientObject;
107 return nullptr;
108 }
109 return thisVar;
110 }
111
GetTextInputClientInstance(napi_env env)112 napi_value JsTextInputClientEngine::GetTextInputClientInstance(napi_env env)
113 {
114 napi_value instance = nullptr;
115 napi_value cons = nullptr;
116 if (napi_get_reference_value(env, TICRef_, &cons) != napi_ok) {
117 IMSA_HILOGE("JsTextInputClientEngine::napi_get_reference_value not ok");
118 return nullptr;
119 }
120 if (napi_new_instance(env, cons, 0, nullptr, &instance) != napi_ok) {
121 IMSA_HILOGE("JsTextInputClientEngine::napi_new_instance not ok");
122 return nullptr;
123 }
124 return instance;
125 }
126
GetNumberProperty(napi_env env,napi_value jsNumber)127 int32_t JsTextInputClientEngine::GetNumberProperty(napi_env env, napi_value jsNumber)
128 {
129 int32_t number;
130 if (napi_get_value_int32(env, jsNumber, &number) != napi_ok) {
131 IMSA_HILOGE("GetNumberProperty error");
132 }
133 return number;
134 }
135
GetStringProperty(napi_env env,napi_value jsString)136 std::string JsTextInputClientEngine::GetStringProperty(napi_env env, napi_value jsString)
137 {
138 char propValue[MAX_VALUE_LEN] = {0};
139 size_t propLen;
140 if (napi_get_value_string_utf8(env, jsString, propValue, MAX_VALUE_LEN, &propLen) != napi_ok) {
141 IMSA_HILOGE("GetStringProperty error");
142 return "";
143 }
144 return std::string(propValue);
145 }
146
GetResult(napi_env env,std::string & text)147 napi_value JsTextInputClientEngine::GetResult(napi_env env, std::string &text)
148 {
149 napi_value jsText = nullptr;
150 napi_create_string_utf8(env, text.c_str(), NAPI_AUTO_LENGTH, &jsText);
151 return jsText;
152 }
153
GetResultEditorAttribute(napi_env env,std::shared_ptr<GetEditorAttributeContext> getEditorAttribute)154 napi_value JsTextInputClientEngine::GetResultEditorAttribute(napi_env env,
155 std::shared_ptr<GetEditorAttributeContext> getEditorAttribute)
156 {
157 napi_value editorAttribute = nullptr;
158 napi_create_object(env, &editorAttribute);
159
160 napi_value jsValue = nullptr;
161 napi_create_int32(env, getEditorAttribute->enterKeyType, &jsValue);
162 napi_set_named_property(env, editorAttribute, "enterKeyType", jsValue);
163
164 napi_value jsMethodId = nullptr;
165 napi_create_int32(env, getEditorAttribute->inputPattern, &jsMethodId);
166 napi_set_named_property(env, editorAttribute, "inputPattern", jsMethodId);
167
168 return editorAttribute;
169 }
170
GetAction(napi_env env,napi_value argv,std::shared_ptr<SendKeyFunctionContext> ctxt)171 napi_status JsTextInputClientEngine::GetAction(napi_env env, napi_value argv,
172 std::shared_ptr<SendKeyFunctionContext> ctxt)
173 {
174 napi_valuetype valueType = napi_undefined;
175 napi_status status = napi_generic_failure;
176 status = napi_typeof(env, argv, &valueType);
177 if (valueType == napi_number) {
178 ctxt->action = GetNumberProperty(env, argv);
179 }
180 return status;
181 }
182
GetDeleteForwardLength(napi_env env,napi_value argv,std::shared_ptr<DeleteForwardContext> ctxt)183 napi_status JsTextInputClientEngine::GetDeleteForwardLength(napi_env env, napi_value argv,
184 std::shared_ptr<DeleteForwardContext> ctxt)
185 {
186 napi_valuetype valueType = napi_undefined;
187 napi_status status = napi_generic_failure;
188 status = napi_typeof(env, argv, &valueType);
189 if (valueType == napi_number) {
190 ctxt->length = GetNumberProperty(env, argv);
191 }
192 return status;
193 }
194
GetMoveCursorParam(napi_env env,napi_value argv,std::shared_ptr<MoveCursorContext> ctxt)195 napi_status JsTextInputClientEngine::GetMoveCursorParam(
196 napi_env env, napi_value argv, std::shared_ptr<MoveCursorContext> ctxt)
197 {
198 napi_valuetype valueType = napi_undefined;
199 napi_status status = napi_generic_failure;
200 status = napi_typeof(env, argv, &valueType);
201 if (valueType == napi_number) {
202 ctxt->num = GetNumberProperty(env, argv);
203 }
204 return status;
205 }
206
GetDeleteBackwardLength(napi_env env,napi_value argv,std::shared_ptr<DeleteBackwardContext> ctxt)207 napi_status JsTextInputClientEngine::GetDeleteBackwardLength(napi_env env, napi_value argv,
208 std::shared_ptr<DeleteBackwardContext> ctxt)
209 {
210 napi_valuetype valueType = napi_undefined;
211 napi_status status = napi_generic_failure;
212 status = napi_typeof(env, argv, &valueType);
213 if (valueType == napi_number) {
214 ctxt->length = GetNumberProperty(env, argv);
215 }
216 return status;
217 }
218
GetInsertText(napi_env env,napi_value argv,std::shared_ptr<InsertTextContext> ctxt)219 napi_status JsTextInputClientEngine::GetInsertText(napi_env env, napi_value argv,
220 std::shared_ptr<InsertTextContext> ctxt)
221 {
222 napi_valuetype valueType = napi_undefined;
223 napi_status status = napi_generic_failure;
224 status = napi_typeof(env, argv, &valueType);
225 if (valueType == napi_string) {
226 ctxt->text = GetStringProperty(env, argv);
227 }
228 return status;
229 }
230
GetForwardLength(napi_env env,napi_value argv,std::shared_ptr<GetForwardContext> ctxt)231 napi_status JsTextInputClientEngine::GetForwardLength(napi_env env, napi_value argv,
232 std::shared_ptr<GetForwardContext> ctxt)
233 {
234 napi_valuetype valueType = napi_undefined;
235 napi_status status = napi_generic_failure;
236 status = napi_typeof(env, argv, &valueType);
237 if (valueType == napi_number) {
238 ctxt->length = GetNumberProperty(env, argv);
239 }
240 return status;
241 }
242
GetBackwardLength(napi_env env,napi_value argv,std::shared_ptr<GetBackwardContext> ctxt)243 napi_status JsTextInputClientEngine::GetBackwardLength(napi_env env, napi_value argv,
244 std::shared_ptr<GetBackwardContext> ctxt)
245 {
246 napi_valuetype valueType = napi_undefined;
247 napi_status status = napi_generic_failure;
248 status = napi_typeof(env, argv, &valueType);
249 if (valueType == napi_number) {
250 ctxt->length = GetNumberProperty(env, argv);
251 }
252 return status;
253 }
254
SendKeyFunction(napi_env env,napi_callback_info info)255 napi_value JsTextInputClientEngine::SendKeyFunction(napi_env env, napi_callback_info info)
256 {
257 auto ctxt = std::make_shared<SendKeyFunctionContext>();
258 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
259 napi_status status = napi_generic_failure;
260 napi_valuetype valueType = napi_undefined;
261 napi_typeof(env, argv[0], &valueType);
262 if (argc < 1) {
263 JsUtils::ThrowException(
264 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
265 return status;
266 }
267 if (valueType != napi_number) {
268 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'action'", TypeCode::TYPE_NUMBER);
269 return status;
270 }
271 status = GetAction(env, argv[0], ctxt);
272 return status;
273 };
274 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
275 napi_status status = napi_get_boolean(env, ctxt->isSendKeyFunction, result);
276 return status;
277 };
278 auto exec = [ctxt](AsyncCall::Context *ctx) {
279 int32_t code = InputMethodAbility::GetInstance()->SendFunctionKey(ctxt->action);
280 if (code == ErrorCode::NO_ERROR) {
281 ctxt->status = napi_ok;
282 ctxt->SetState(ctxt->status);
283 ctxt->isSendKeyFunction = true;
284 } else {
285 ctxt->SetErrorCode(code);
286 }
287 };
288 ctxt->SetAction(std::move(input), std::move(output));
289 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
290 return asyncCall.Call(env, exec);
291 }
292
DeleteForward(napi_env env,napi_callback_info info)293 napi_value JsTextInputClientEngine::DeleteForward(napi_env env, napi_callback_info info)
294 {
295 auto ctxt = std::make_shared<DeleteForwardContext>();
296 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
297 napi_status status = napi_generic_failure;
298 napi_valuetype valueType = napi_undefined;
299 napi_typeof(env, argv[0], &valueType);
300 if (argc < 1) {
301 JsUtils::ThrowException(
302 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
303 return status;
304 }
305 if (valueType != napi_number) {
306 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'length'", TypeCode::TYPE_NUMBER);
307 return status;
308 }
309 status = GetDeleteForwardLength(env, argv[0], ctxt);
310 return status;
311 };
312 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
313 napi_status status = napi_get_boolean(env, ctxt->isDeleteForward, result);
314 return status;
315 };
316 auto exec = [ctxt](AsyncCall::Context *ctx) {
317 int32_t code = InputMethodAbility::GetInstance()->DeleteForward(ctxt->length);
318 if (code == ErrorCode::NO_ERROR) {
319 ctxt->status = napi_ok;
320 ctxt->SetState(ctxt->status);
321 ctxt->isDeleteForward = true;
322 } else {
323 ctxt->SetErrorCode(code);
324 }
325 };
326 ctxt->SetAction(std::move(input), std::move(output));
327 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
328 return asyncCall.Call(env, exec);
329 }
330
DeleteBackward(napi_env env,napi_callback_info info)331 napi_value JsTextInputClientEngine::DeleteBackward(napi_env env, napi_callback_info info)
332 {
333 auto ctxt = std::make_shared<DeleteBackwardContext>();
334 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
335 napi_status status = napi_generic_failure;
336 napi_valuetype valueType = napi_undefined;
337 napi_typeof(env, argv[0], &valueType);
338 if (argc < 1) {
339 JsUtils::ThrowException(
340 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
341 return status;
342 }
343 if (valueType != napi_number) {
344 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'length", TypeCode::TYPE_NUMBER);
345 return status;
346 }
347 status = GetDeleteBackwardLength(env, argv[0], ctxt);
348 return status;
349 };
350 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
351 napi_status status = napi_get_boolean(env, ctxt->isDeleteBackward, result);
352 return status;
353 };
354 auto exec = [ctxt](AsyncCall::Context *ctx) {
355 int32_t code = InputMethodAbility::GetInstance()->DeleteBackward(ctxt->length);
356 if (code == ErrorCode::NO_ERROR) {
357 ctxt->status = napi_ok;
358 ctxt->SetState(ctxt->status);
359 ctxt->isDeleteBackward = true;
360 } else {
361 ctxt->SetErrorCode(code);
362 }
363 };
364 ctxt->SetAction(std::move(input), std::move(output));
365 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
366 return asyncCall.Call(env, exec);
367 }
368
InsertText(napi_env env,napi_callback_info info)369 napi_value JsTextInputClientEngine::InsertText(napi_env env, napi_callback_info info)
370 {
371 auto ctxt = std::make_shared<InsertTextContext>();
372 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
373 napi_status status = napi_generic_failure;
374 napi_valuetype valueType = napi_undefined;
375 napi_typeof(env, argv[0], &valueType);
376 if (argc < 1) {
377 JsUtils::ThrowException(
378 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
379 return status;
380 }
381 if (valueType != napi_string) {
382 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'text'", TypeCode::TYPE_STRING);
383 return status;
384 }
385 status = GetInsertText(env, argv[0], ctxt);
386 return status;
387 };
388 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
389 napi_status status = napi_get_boolean(env, ctxt->isInsertText, result);
390 return status;
391 };
392 auto exec = [ctxt](AsyncCall::Context *ctx) {
393 int32_t code = InputMethodAbility::GetInstance()->InsertText(ctxt->text);
394 if (code == ErrorCode::NO_ERROR) {
395 ctxt->status = napi_ok;
396 ctxt->SetState(ctxt->status);
397 ctxt->isInsertText = true;
398 } else {
399 ctxt->SetErrorCode(code);
400 }
401 };
402 ctxt->SetAction(std::move(input), std::move(output));
403 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
404 return asyncCall.Call(env, exec);
405 }
406
GetForward(napi_env env,napi_callback_info info)407 napi_value JsTextInputClientEngine::GetForward(napi_env env, napi_callback_info info)
408 {
409 auto ctxt = std::make_shared<GetForwardContext>();
410 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
411 napi_status status = napi_generic_failure;
412 napi_valuetype valueType = napi_undefined;
413 napi_typeof(env, argv[0], &valueType);
414 if (argc < 1) {
415 JsUtils::ThrowException(
416 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
417 return status;
418 }
419 if (valueType != napi_number) {
420 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'length'", TypeCode::TYPE_NUMBER);
421 return status;
422 }
423 status = GetForwardLength(env, argv[0], ctxt);
424 return status;
425 };
426 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
427 napi_value data = GetResult(env, ctxt->text);
428 *result = data;
429 return napi_ok;
430 };
431 auto exec = [ctxt](AsyncCall::Context *ctx) {
432 std::u16string temp;
433 int32_t code = InputMethodAbility::GetInstance()->GetTextBeforeCursor(ctxt->length, temp);
434 if (code == ErrorCode::NO_ERROR) {
435 ctxt->status = napi_ok;
436 ctxt->SetState(ctxt->status);
437 ctxt->text = Str16ToStr8(temp);
438 } else {
439 ctxt->SetErrorCode(code);
440 }
441 };
442 ctxt->SetAction(std::move(input), std::move(output));
443 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
444 return asyncCall.Call(env, exec);
445 }
446
GetBackward(napi_env env,napi_callback_info info)447 napi_value JsTextInputClientEngine::GetBackward(napi_env env, napi_callback_info info)
448 {
449 auto ctxt = std::make_shared<GetBackwardContext>();
450 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
451 napi_status status = napi_generic_failure;
452 napi_valuetype valueType = napi_undefined;
453 napi_typeof(env, argv[0], &valueType);
454 if (argc < 1) {
455 JsUtils::ThrowException(
456 env, IMFErrorCode::EXCEPTION_PARAMCHECK, " should 1 or 2 parameters!", TypeCode::TYPE_NONE);
457 return status;
458 }
459 if (valueType != napi_number) {
460 JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, " 'length'", TypeCode::TYPE_NUMBER);
461 return status;
462 }
463 status = GetBackwardLength(env, argv[0], ctxt);
464 return status;
465 };
466 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
467 napi_value data = GetResult(env, ctxt->text);
468 *result = data;
469 return napi_ok;
470 };
471 auto exec = [ctxt](AsyncCall::Context *ctx) {
472 std::u16string temp;
473 int32_t code = InputMethodAbility::GetInstance()->GetTextAfterCursor(ctxt->length, temp);
474 if (code == ErrorCode::NO_ERROR) {
475 ctxt->status = napi_ok;
476 ctxt->SetState(ctxt->status);
477 ctxt->text = Str16ToStr8(temp);
478 } else {
479 ctxt->SetErrorCode(code);
480 }
481 };
482 ctxt->SetAction(std::move(input), std::move(output));
483 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 1);
484 return asyncCall.Call(env, exec);
485 }
486
GetEditorAttribute(napi_env env,napi_callback_info info)487 napi_value JsTextInputClientEngine::GetEditorAttribute(napi_env env, napi_callback_info info)
488 {
489 auto ctxt = std::make_shared<GetEditorAttributeContext>();
490 auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
491 return napi_ok;
492 };
493 auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
494 napi_value data = GetResultEditorAttribute(env, ctxt);
495 *result = data;
496 return napi_ok;
497 };
498 auto exec = [ctxt](AsyncCall::Context *ctx) {
499 int32_t typeCode = InputMethodAbility::GetInstance()->GetEnterKeyType(ctxt->enterKeyType);
500 int32_t patternCode = InputMethodAbility::GetInstance()->GetInputPattern(ctxt->inputPattern);
501 if (typeCode == ErrorCode::NO_ERROR && patternCode == ErrorCode::NO_ERROR) {
502 ctxt->status = napi_ok;
503 ctxt->SetState(ctxt->status);
504 } else {
505 typeCode == ErrorCode::NO_ERROR ? ctxt->SetErrorCode(patternCode) : ctxt->SetErrorCode(typeCode);
506 }
507 };
508 ctxt->SetAction(std::move(input), std::move(output));
509 AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 0);
510 return asyncCall.Call(env, exec);
511 }
512 } // namespace MiscServices
513 } // namespace OHOS
514