diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 2331587731dfc411f3935be36d6a605bf3a7fb2c..9f17da9a2a3c20017ff0f043a6b08ba3bb20c990 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -58,6 +58,7 @@ group("napi_packages") { "${ability_runtime_napi_path}/callee:callee_napi", "${ability_runtime_napi_path}/caller:caller_napi", "${ability_runtime_napi_path}/completion_handler_for_atomic_service:completionhandlerforatomicservice", + "${ability_runtime_napi_path}/completion_handler_for_abilitystartcallback:completionhandlerforabilitystartcallback", "${ability_runtime_napi_path}/configuration_constant:configurationconstant", "${ability_runtime_napi_path}/configuration_constant:configurationconstant_napi", "${ability_runtime_napi_path}/dataUriUtils:datauriutils_napi", diff --git a/frameworks/js/napi/completion_handler_for_abilitystartcallback/BUILD.gn b/frameworks/js/napi/completion_handler_for_abilitystartcallback/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e3c8d0f937212aeddf33cf8e052e4808ac927519 --- /dev/null +++ b/frameworks/js/napi/completion_handler_for_abilitystartcallback/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("completionhandlerforabilitystartcallback") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ + "${ability_runtime_services_path}/common/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + + sources = [ "completion_handler_for_abilitystartcallback_module.cpp" ] + + deps = [] + + external_deps = [ + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/completion_handler_for_abilitystartcallback/completion_handler_for_abilitystartcallback_module.cpp b/frameworks/js/napi/completion_handler_for_abilitystartcallback/completion_handler_for_abilitystartcallback_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f9d285d30b62fa8158ad23879b1e59d5bb358f3 --- /dev/null +++ b/frameworks/js/napi/completion_handler_for_abilitystartcallback/completion_handler_for_abilitystartcallback_module.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hilog_tag_wrapper.h" +#include "native_engine/native_engine.h" +#include "ability_failure_code.h" + +namespace OHOS { +namespace AbilityRuntime { + +static napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value) +{ + napi_status status; + napi_value itemName; + napi_value itemValue; + + NAPI_CALL_BASE(env, status = napi_create_string_utf8(env, name, NAPI_AUTO_LENGTH, &itemName), status); + NAPI_CALL_BASE(env, status = napi_create_int32(env, value, &itemValue), status); + + NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemName, itemValue), status); + NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemValue, itemName), status); + + return napi_ok; +} + +static napi_value InitFailureCodeObject(napi_env env) +{ + napi_value object; + NAPI_CALL(env, napi_create_object(env, &object)); + NAPI_CALL(env, SetEnumItem(env, object, "FAILURE_CODE_SYSTEM_MALFUNCTION", + static_cast(FailureCode::FAILURE_CODE_SYSTEM_MALFUNCTION))); + NAPI_CALL(env, SetEnumItem(env, object, "FAILURE_CODE_USER_CANCEL", + static_cast(FailureCode::FAILURE_CODE_USER_CANCEL))); + return object; +} + +static napi_value CompletionHandlerForAbilityStartCallbackInit(napi_env env, napi_value exports) +{ + napi_value failureCode = InitFailureCodeObject(env); + if (failureCode == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "null failureCode"); + return nullptr; + } + + napi_property_descriptor exportObjs[] = { + DECLARE_NAPI_PROPERTY("FailureCode", failureCode), + }; + + napi_status status = napi_define_properties(env, exports, sizeof(exportObjs) / sizeof(exportObjs[0]), exportObjs); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::JSNAPI, "define properties failed"); + return nullptr; + } + + return exports; +} + +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 0, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = CompletionHandlerForAbilityStartCallbackInit, + .nm_modname = "app.ability.CompletionHandlerForAbilityStartCallback", + .nm_priv = (static_cast(0)), + .reserved = {0} +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&_module); +} +} +} diff --git a/services/abilitymgr/include/ability_failure_code.h b/services/abilitymgr/include/ability_failure_code.h new file mode 100644 index 0000000000000000000000000000000000000000..ae5521b5c30d0e3a8083a2441208c8c7f3d04325 --- /dev/null +++ b/services/abilitymgr/include/ability_failure_code.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ABILITY_FAILURE_CODE_H +#define OHOS_ABILITY_RUNTIME_ABILITY_FAILURE_CODE_H + +namespace OHOS { +namespace AbilityRuntime { +enum class FailureCode { + FAILURE_CODE_SYSTEM_MALFUNCTION = 0, + FAILURE_CODE_USER_CANCEL = 1, +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_FAILURE_CODE_H \ No newline at end of file