fauilure code

Signed-off-by: zexin_c <chenzexin14@huawei.com>
This commit is contained in:
zexin_c
2025-09-22 11:03:59 +08:00
parent b3cf2feeeb
commit b2ce1e3ab2
4 changed files with 161 additions and 0 deletions
+1
View File
@@ -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",
@@ -0,0 +1,42 @@
# 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 = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
"napi:ace_napi",
]
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -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 "ability_failure_code.h"
#include "hilog_tag_wrapper.h"
#include "native_engine/native_engine.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<int32_t>(FailureCode::FAILURE_CODE_SYSTEM_MALFUNCTION)));
NAPI_CALL(env, SetEnumItem(env, object, "FAILURE_CODE_USER_CANCEL",
static_cast<int32_t>(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("AbilityStartFailureCode", 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<void *>(0)),
.reserved = {0}
};
/*
* The module registration.
*/
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&_module);
}
}
}
@@ -0,0 +1,27 @@
/*
* 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.
*/
#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