From 0f577087cec2763117ed0c0570749b8dc143d086 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Tue, 3 Jun 2025 11:31:07 +0800 Subject: [PATCH] add AutoStartupInfo Signed-off-by: zhangzezhong --- frameworks/ets/ani/BUILD.gn | 1 + .../ability_auto_startup_callback/BUILD.gn | 61 ++++++ .../ets_ability_auto_startup_manager_utils.h | 29 +++ ...ets_ability_auto_startup_manager_utils.cpp | 188 ++++++++++++++++++ frameworks/ets/ets/BUILD.gn | 17 ++ .../ets/ets/application/AutoStartupInfo.ets | 45 +++++ 6 files changed, 341 insertions(+) create mode 100644 frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn create mode 100644 frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h create mode 100644 frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp create mode 100644 frameworks/ets/ets/application/AutoStartupInfo.ets diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index f487ec8a122..3714c230fbb 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -28,5 +28,6 @@ group("ani_packages") { "${ability_runtime_path}/frameworks/ets/ani/uri_permission_manager:uri_permission_manager_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/wantagent:aniwantagent", "${ability_runtime_path}/frameworks/ets/ani/application:application_ani", + "${ability_runtime_path}/frameworks/ets/ani/ability_auto_startup_callback:ability_auto_startup_manager_ani_kit", ] } \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn b/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn new file mode 100644 index 00000000000..a7f04478ea2 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2023 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("ability_auto_startup_manager_ani_kit") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + include_dirs = [ + "./include", + "${ability_runtime_utils_path}/global/constant", + ] + + sources = [ + "./src/ets_ability_auto_startup_manager_utils.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + ] + + external_deps = [ + "ability_base:session_info", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + "runtime_core:ani", + "napi:ace_napi", + "window_manager:libwm", + ] + + if (ability_runtime_graphics) { + defines = [ + "SUPPORT_GRAPHICS", + "SUPPORT_SCREEN", + ] + } + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h new file mode 100644 index 00000000000..ff352f7c8c1 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H +#define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H + +#include "auto_startup_info.h" +#include "sts_runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +bool UnwrapAutoStartupInfo(ani_env *env, ani_object param, AutoStartupInfo &info); +ani_object CreateEtsAutoStartupInfoArray(ani_env *env, const std::vector &infoList); +ani_object WrapAutoStartupInfo(ani_env *env, const AutoStartupInfo &info); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp new file mode 100644 index 00000000000..f49d50092d5 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2023-2024 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 "ets_ability_auto_startup_manager_utils.h" + +#include "global_constant.h" +#include "hilog_tag_wrapper.h" +#include "ani_common_util.h" + +namespace OHOS { +namespace AbilityRuntime { +bool UnwrapAutoStartupInfo(ani_env *env, ani_object param, AutoStartupInfo &info) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "env is nullptr"); + return false; + } + + if (!AppExecFwk::GetStringProperty(env, param, "bundleName", info.bundleName)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "convert bundleName failed"); + return false; + } + + if (!AppExecFwk::GetStringProperty(env, param, "abilityName", info.abilityName)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "convert abilityName failed"); + return false; + } + + ani_double appCloneIndex = 0.0; + if (AppExecFwk::IsExistsProperty(env, param, "appCloneIndex")) { + if (!AppExecFwk::GetDoubleOrUndefined(env, param, "appCloneIndex", appCloneIndex)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "convert appCloneIndex failed"); + return false; + } + } + info.appCloneIndex = static_cast(appCloneIndex); + + AppExecFwk::GetStringProperty(env, param, "moduleName", info.moduleName); + return true; +} + +ani_object CreateEtsAutoStartupInfoArray(ani_env *env, const std::vector &infoList) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + ani_class arratCls = nullptr; + ani_status status = ANI_OK; + + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "env is nullptr"); + return nullptr; + } + + status = env->FindClass("Lescompat/Array", &arratCls); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "FindClass failed satus : %{public}d", status); + return nullptr; + } + + ani_method arrayCtor; + status = env->Class_FindMethod(arratCls, "", "I:V", &arrayCtor); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Class_FindMethod failed satus : %{public}d", status); + return nullptr; + } + + ani_object arrayObj; + status = env->Object_New(arratCls, arrayCtor, &arrayObj, infoList.size()); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Objiect_New failed satus : %{public}d", status); + return nullptr; + } + + ani_size index = 0; + for (auto &startUpInfo : infoList) { + ani_object ani_info = WrapAutoStartupInfo(env, startUpInfo); + if (ani_info == nullptr) { + TAG_LOGW(AAFwkTag::AUTO_STARTUP, "null ani_info"); + break; + } + status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", index, ani_info); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Object_CallMethodByName_void failed satus : %{public}d", status); + break; + } + index++; + } + return arrayObj; +} + +bool SetAutoStartupInfo(ani_env *env, ani_object object, const AutoStartupInfo &info) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "env is nullptr"); + return false; + } + + ani_status status = ANI_OK; + status = env->Object_SetPropertyByName_Ref(object, "bundleName", + AppExecFwk::GetAniString(env, info.bundleName)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "bundleName failed status:%{public}d", status); + return false; + } + + status = env->Object_SetPropertyByName_Ref(object, "abilityName", + AppExecFwk::GetAniString(env, info.abilityName)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "abilityName failed status:%{public}d", status); + return false; + } + + status = env->Object_SetPropertyByName_Ref(object, "moduleName", + AppExecFwk::GetAniString(env, info.moduleName)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "moduleName failed status:%{public}d", status); + return false; + } + + status = env->Object_SetPropertyByName_Ref(object, "abilityTypeName", + AppExecFwk::GetAniString(env, info.abilityTypeName)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "abilityTypeName failed status:%{public}d", status); + return false; + } + + if (info.appCloneIndex >= 0 && info.appCloneIndex < GlobalConstant::MAX_APP_CLONE_INDEX) { + status = env->Object_SetPropertyByName_Ref(object, "appCloneIndex", + AppExecFwk::GetAniString(env, info.abilityTypeName)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "appCloneIndex failed status:%{public}d", status); + return false; + } + } + return true; +} + +ani_object WrapAutoStartupInfo(ani_env *env, const AutoStartupInfo &info) +{ + ani_class cls {}; + ani_status status = ANI_ERROR; + ani_method method {}; + ani_object object = nullptr; + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null env"); + return nullptr; + } + if ((status = env->FindClass("Lapplication/AutoStartupInfo/AutoStartupInfoImpl;", &cls)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "FindClass failed status : %{public}d", status); + return nullptr; + } + if (cls == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null cls"); + return nullptr; + } + if ((status = env->Class_FindMethod(cls, "", ":V", &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "find ctor failed status : %{public}d", status); + return nullptr; + } + if ((status = env->Object_New(cls, method, &object)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "Object_New failed status : %{public}d", status); + return nullptr; + } + if (object == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null object"); + return nullptr; + } + if (!SetAutoStartupInfo(env, object, info)) { + TAG_LOGE(AAFwkTag::APPMGR, "SetAutoStartupInfo failed"); + return nullptr; + } + + return object; +} + +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 92dc4143941..bc93decc6dd 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -515,6 +515,22 @@ ohos_prebuilt_etc("ability_runtime_app_state_data_abc_etc") { deps = [ ":ability_runtime_app_state_data_abc" ] } +generate_static_abc("ability_runtime_auto_startup_info_abc") { + base_url = "./" + files = [ "./application/AutoStartupInfo.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_auto_startup_info_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_auto_startup_info_abc_etc") { + source = "$target_out_dir/ability_runtime_auto_startup_info_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_auto_startup_info_abc" ] +} + generate_static_abc("ability_runtime_process_data_abc") { base_url = "./" files = [ "./application/ProcessData.ets" ] @@ -839,6 +855,7 @@ group("ets_packages") { ":ability_runtime_ability_utils_abc_etc", ":ability_runtime_app_manager_abc_etc", ":ability_runtime_app_state_data_abc_etc", + ":ability_runtime_auto_startup_info_abc_etc", ":ability_runtime_application_context_abc_etc", ":ability_runtime_base_context_abc_etc", ":ability_runtime_configuration_abc_etc", diff --git a/frameworks/ets/ets/application/AutoStartupInfo.ets b/frameworks/ets/ets/application/AutoStartupInfo.ets new file mode 100644 index 00000000000..74f972e5873 --- /dev/null +++ b/frameworks/ets/ets/application/AutoStartupInfo.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023-2024 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. + */ + +/** + * @file + * @kit AbilityKit + */ + +/** + * The class of auto startup info. + * + * @typedef AutoStartupInfo + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @systemapi + * @stagemodelonly + * @since arkts {'1.1':'11', '1.2':'20'} + * @arkts 1.1&1.2 + */ +export interface AutoStartupInfo { + bundleName: string; + moduleName?: string; + abilityName: string; + abilityTypeName?: string; + appCloneIndex?: number; +} + +export default class AutoStartupInfoImpl implements AutoStartupInfo { + bundleName: string = ''; + moduleName?: string; + abilityName: string = ''; + abilityTypeName?:string; + appCloneIndex?: number; +} \ No newline at end of file -- Gitee