diff --git a/bundle.json b/bundle.json index 7061fe242fb6186c657faed14f6761f2a5559aaf..a3a95d1a798587d18f853b6287f0981b56997a88 100644 --- a/bundle.json +++ b/bundle.json @@ -342,6 +342,7 @@ "header": { "header_base": "//foundation/ability/ability_runtime/frameworks/ets/ani/ani_common/include", "header_files": [ + "ani_common_ability_result.h", "ani_common_start_options.h", "ani_common_want.h", "ets_native_reference.h" diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 2d2fb6e34bf483b580165c28b40b54967f247181..6402f9263dfcc35c94afdada52ba7ee5b9c73f31 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -17,6 +17,8 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") group("ani_packages") { deps = [ "${ability_runtime_path}/frameworks/ets/ani/ability_delegator:ability_delegator_registry_ani_kit", + "${ability_runtime_path}/frameworks/ets/ani/ability_manager:ability_ability_manager_abc_etc", + "${ability_runtime_path}/frameworks/ets/ani/ability_manager:ability_ability_manager_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", "${ability_runtime_path}/frameworks/ets/ani/native_constructor:context_ani", "${ability_runtime_path}/frameworks/ets/ani/uri_permission_manager:uri_permission_manager_ani_kit", diff --git a/frameworks/ets/ani/ability_manager/BUILD.gn b/frameworks/ets/ani/ability_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..02b785e572685f80d41cf8f09ee2e94b941f7fcb --- /dev/null +++ b/frameworks/ets/ani/ability_manager/BUILD.gn @@ -0,0 +1,84 @@ +# 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/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("ability_ability_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_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_services_path}/common/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/inner_api/runtime/include", + ] + + configs = [] + + public_configs = [] + + sources = [ "./src/ets_ability_manager.cpp" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + ] + + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + "runtime_core:ani", + "samgr:samgr_proxy", + ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +generate_static_abc("ability_ability_manager_abc") { + base_url = "./ets" + files = [ "./ets/@ohos.app.ability.abilityManager.ets" ] + + dst_file = "$target_out_dir/ability_ability_manager.abc" + out_puts = [ "$target_out_dir/ability_ability_manager.abc" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_ability_manager.abc" +} + +ohos_prebuilt_etc("ability_ability_manager_abc_etc") { + source = "$target_out_dir/ability_ability_manager.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_ability_manager_abc" ] +} diff --git a/frameworks/ets/ani/ability_manager/ets/@ohos.app.ability.abilityManager.ets b/frameworks/ets/ani/ability_manager/ets/@ohos.app.ability.abilityManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..257a2191f0881d348de6aa554b5a6e99aa0911d0 --- /dev/null +++ b/frameworks/ets/ani/ability_manager/ets/@ohos.app.ability.abilityManager.ets @@ -0,0 +1,39 @@ +/* + * 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 AbilityStateData from 'application.AbilityStateData'; + +export default namespace abilityManager { + loadLibrary("ability_ability_manager_ani_kit.z") + + export native function nativeGetForegroundUIAbilities(): Array; + export function getForegroundUIAbilities():Promise> { + let p = new Promise>((resolve: (data: Array) => void, reject: (error: Error) => void): void => { + let executeFunc = (): Array => { + return nativeGetForegroundUIAbilities(); + }; + let p1 = taskpool.execute(executeFunc); + p1.then((e :NullishType)=>{ + let abilities: Array = e as Array; + resolve(abilities); + }, (err: Error): void => { + reject(err); + }); + }); + return p; + } +} + + diff --git a/frameworks/ets/ani/ability_manager/include/ets_ability_manager.h b/frameworks/ets/ani/ability_manager/include/ets_ability_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..6e70dd0e807d6fdc2136047f95ef532df198e914 --- /dev/null +++ b/frameworks/ets/ani/ability_manager/include/ets_ability_manager.h @@ -0,0 +1,26 @@ +/* + * 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_ETS_ABILITY_MANAGER_H +#define OHOS_ABILITY_RUNTIME_ETS_ABILITY_MANAGER_H + +typedef struct __ani_env ani_env; + +namespace OHOS { +namespace EtsAbilityManager { +void StsAbilityManagerRegistryInit(ani_env *env); +} // namespace EtsAbilityManager +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_ABILITY_MANAGER_H diff --git a/frameworks/ets/ani/ability_manager/src/ets_ability_manager.cpp b/frameworks/ets/ani/ability_manager/src/ets_ability_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83211e052dd538fdb876ce76aa920a210dc86a74 --- /dev/null +++ b/frameworks/ets/ani/ability_manager/src/ets_ability_manager.cpp @@ -0,0 +1,135 @@ +/* + * 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 "ets_ability_manager.h" + +#include "ability_business_error.h" +#include "ability_manager_interface.h" +#include "ani_common_ability_state_data.h" +#include "ets_error_utils.h" +#include "hilog_tag_wrapper.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace EtsAbilityManager { +sptr GetAbilityManagerInstance() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr abilityManagerObj = + systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + return iface_cast(abilityManagerObj); +} + +static ani_object GetForegroundUIAbilities(ani_env *env) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "call GetForegroundUIAbilities"); + + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null env"); + return nullptr; + } + + sptr abilityManager = GetAbilityManagerInstance(); + if (abilityManager == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManager is null"); + AbilityRuntime::EtsErrorUtil::EtsErrorUtil::ThrowErrorByNativeErr(env, + static_cast(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER)); + return nullptr; + } + std::vector list; + int32_t ret = abilityManager->GetForegroundUIAbilities(list); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed: ret=%{public}d", ret); + AbilityRuntime::AbilityErrorCode code = AbilityRuntime::GetJsErrorCodeByNativeError(ret); + AbilityRuntime::EtsErrorUtil::EtsErrorUtil::ThrowErrorByNativeErr(env, static_cast(code)); + return nullptr; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "GetForegroundUIAbilities succeeds, list.size=%{public}zu", list.size()); + ani_object aniArray = AppExecFwk::CreateAniAbilityStateDataArray(env, list); + if (aniArray == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null aniArray"); + AbilityRuntime::EtsErrorUtil::EtsErrorUtil::ThrowErrorByNativeErr(env, + static_cast(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER)); + return nullptr; + } + return aniArray; +} + +void StsAbilityManagerRegistryInit(ani_env *env) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "call StsAbilityManagerRegistryInit"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null env"); + return; + } + + ani_status status = ANI_ERROR; + if (env->ResetError() != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ResetError failed"); + } + + ani_namespace ns; + status = env->FindNamespace("L@ohos/app/ability/abilityManager/abilityManager;", &ns); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "FindNamespace abilityManager failed status : %{public}d", status); + return; + } + + std::array methods = { + ani_native_function { + "nativeGetForegroundUIAbilities", + ":Lescompat/Array;", + reinterpret_cast(GetForegroundUIAbilities) + }, + }; + + status = env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size()); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Namespace_BindNativeFunctions failed status : %{public}d", status); + } + + if (env->ResetError() != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ResetError failed"); + } +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "in EtsAbilityManager.ANI_Constructor"); + if (vm == nullptr || result == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null vm or result"); + return ANI_INVALID_ARGS; + } + + ani_env *env = nullptr; + ani_status status = ANI_ERROR; + status = vm->GetEnv(ANI_VERSION_1, &env); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "GetEnv failed, status=%{public}d", status); + return ANI_NOT_FOUND; + } + + StsAbilityManagerRegistryInit(env); + *result = ANI_VERSION_1; + TAG_LOGI(AAFwkTag::ABILITYMGR, "EtsAbilityManager.ANI_Constructor finished"); + return ANI_OK; +} +} +} // namespace EtsAbilityManager +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/ani_common/BUILD.gn b/frameworks/ets/ani/ani_common/BUILD.gn index 5053411f2be1caa55cc58de95575c620cf9d9433..f8fa111a369c2a29e494ebfdb8cf925c083ac9c9 100644 --- a/frameworks/ets/ani/ani_common/BUILD.gn +++ b/frameworks/ets/ani/ani_common/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("ani_common") { sources = [ "src/ani_common_ability_result.cpp", + "src/ani_common_ability_state_data.cpp", "src/ani_common_configuration.cpp", "src/ani_common_start_options.cpp", "src/ani_common_util.cpp", @@ -59,6 +60,7 @@ ohos_shared_library("ani_common") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/appkit:app_context", diff --git a/frameworks/ets/ani/ani_common/include/ani_common_ability_state_data.h b/frameworks/ets/ani/ani_common/include/ani_common_ability_state_data.h new file mode 100644 index 0000000000000000000000000000000000000000..d350c812cf506c2ee101ef9c176639d36ed50c8d --- /dev/null +++ b/frameworks/ets/ani/ani_common/include/ani_common_ability_state_data.h @@ -0,0 +1,31 @@ +/* + * 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_RUNNTIME_ANI_COMMON_ABILITY_STATE_DATA_H +#define OHOS_ABILITY_RUNNTIME_ANI_COMMON_ABILITY_STATE_DATA_H + +#include "ability_state_data.h" +#include "ani.h" + +namespace OHOS { +namespace AppExecFwk { + ani_object WrapAbilityStateData(ani_env *env, const AbilityStateData &data); + ani_object WrapAbilityStateDataInner(ani_env *env, ani_class cls, ani_object object, + const AbilityStateData &data); + ani_object CreateAniAbilityStateDataArray(ani_env *env, const std::vector &list); +} // namespace AppExecFwk +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNNTIME_ANI_COMMON_ABILITY_STATE_DATA_H \ No newline at end of file diff --git a/frameworks/ets/ani/ani_common/include/ani_common_util.h b/frameworks/ets/ani/ani_common/include/ani_common_util.h index 63dff5f2f1dbc1241cdf6d0a41805975d4852d95..c15c9b37b75eb165ebb4ea5a83e211c0a936b2d3 100644 --- a/frameworks/ets/ani/ani_common/include/ani_common_util.h +++ b/frameworks/ets/ani/ani_common/include/ani_common_util.h @@ -45,6 +45,8 @@ bool SetFieldRefByName(ani_env *env, ani_class cls, ani_object object, const cha bool GetStdString(ani_env *env, ani_string str, std::string &value); ani_string GetAniString(ani_env *env, const std::string &str); bool GetAniStringArray(ani_env *env, const std::vector &values, ani_array_ref *value); +ani_object CreateInt(ani_env *env, ani_int value); +bool SetOptionalFieldInt(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, int value); ani_object CreateDouble(ani_env *env, ani_double value); ani_object CreateBoolean(ani_env *env, ani_boolean value); diff --git a/frameworks/ets/ani/ani_common/src/ani_common_ability_state_data.cpp b/frameworks/ets/ani/ani_common/src/ani_common_ability_state_data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8290223ddd4ded8b8bb3834d61a0e551a1e97131 --- /dev/null +++ b/frameworks/ets/ani/ani_common/src/ani_common_ability_state_data.cpp @@ -0,0 +1,156 @@ +/* + * 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 "ani_common_ability_state_data.h" + +#include "ani_common_util.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +ani_object WrapAbilityStateDataInner(ani_env *env, ani_class cls, ani_object object, + const AbilityStateData &data) +{ + if (env == nullptr || cls == nullptr || object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid args"); + return nullptr; + } + + if (!SetFieldStringByName(env, cls, object, "moduleName", data.moduleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set moduleName failed"); + return nullptr; + } + + if (!SetFieldStringByName(env, cls, object, "bundleName", data.bundleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set bundleName failed"); + return nullptr; + } + + if (!SetFieldStringByName(env, cls, object, "abilityName", data.abilityName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set abilityName failed"); + return nullptr; + } + + if (!SetFieldIntByName(env, cls, object, "pid", data.pid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set pid failed"); + return nullptr; + } + + if (!SetFieldIntByName(env, cls, object, "uid", data.uid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set uid failed"); + return nullptr; + } + + if (!SetFieldIntByName(env, cls, object, "state", data.abilityState)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set state failed"); + return nullptr; + } + + if (!SetFieldIntByName(env, cls, object, "abilityType", data.abilityType)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set type failed"); + return nullptr; + } + + if (!SetFieldBoolByName(env, cls, object, "isAtomicService", data.isAtomicService)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set isAtomicService failed"); + return nullptr; + } + + if (data.appCloneIndex != -1 && !SetOptionalFieldInt(env, cls, object, "appCloneIndex", data.appCloneIndex)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "set appCloneIndex failed"); + return nullptr; + } + + return object; +} + +ani_object WrapAbilityStateData(ani_env *env, const AbilityStateData &data) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null env"); + return nullptr; + } + + ani_class cls = nullptr; + ani_status status = ANI_ERROR; + ani_method ctor = nullptr; + ani_object object = {}; + static const char *className = "Lapplication/AbilityStateData/AbilityStateData;"; + + if ((status = env->FindClass(className, &cls)) != ANI_OK || cls == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "FindClass status : %{public}d or null cls", status); + return nullptr; + } + + if ((status = env->Class_FindMethod(cls, "", ":V", &ctor)) != ANI_OK || ctor == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Class_FindMethod status : %{public}d or null ctor", status); + return nullptr; + } + + if ((status = env->Object_New(cls, ctor, &object)) != ANI_OK || object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Object_New status : %{public}d or null object", status); + return nullptr; + } + + return WrapAbilityStateDataInner(env, cls, object, data); +} + +ani_object CreateAniAbilityStateDataArray(ani_env *env, const std::vector &list) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "call CreateAniAbilityStateDataArray, list.size=%{public}zu", list.size()); + + if (env == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null env"); + return nullptr; + } + + ani_class cls = nullptr; + ani_status status = ANI_ERROR; + ani_method ctor = nullptr; + ani_object object = {}; + static const char *className = "Lescompat/Array;"; + + if ((status = env->FindClass(className, &cls)) != ANI_OK || cls == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "FindClass status : %{public}d or null cls", status); + return nullptr; + } + + if ((status = env->Class_FindMethod(cls, "", "I:V", &ctor)) != ANI_OK || ctor == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Class_FindMethod status : %{public}d or null ctor", status); + return nullptr; + } + + if ((status = env->Object_New(cls, ctor, &object, list.size())) != ANI_OK || object == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Object_New status : %{public}d or null object", status); + return nullptr; + } + + ani_size index = 0; + for (const auto &data : list) { + ani_object obj = WrapAbilityStateData(env, data); + if (obj == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null obj"); + return nullptr; + } + if (ANI_OK != env->Object_CallMethodByName_Void(object, "$_set", "ILstd/core/Object;:V", index, obj)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Object_CallMethodByName_Void failed"); + return nullptr; + } + index++; + } + return object; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp index cecb72225a3df2005c70f2d81ed61bd5f66db9e1..46c2ece55111870f88e406319df1d017bc322d68 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -23,6 +23,7 @@ namespace OHOS { namespace AppExecFwk { constexpr const char* CLASSNAME_DOUBLE = "Lstd/core/Double;"; constexpr const char* CLASSNAME_BOOL = "Lstd/core/Boolean;"; +constexpr const char* CLASSNAME_INT = "Lstd/core/Int;"; constexpr const char* CLASSNAME_ARRAY = "Lescompat/Array;"; constexpr const char* CLASSNAME_ASYNC_CALLBACK_WRAPPER = "Lutils/AbilityUtils/AsyncCallbackWrapper;"; @@ -453,6 +454,50 @@ ani_object CreateBoolean(ani_env *env, ani_boolean value) return obj; } +ani_object CreateInt(ani_env *env, ani_int value) +{ + ani_class cls; + ani_status status = ANI_ERROR; + if ((status = env->FindClass(CLASSNAME_INT, &cls)) != ANI_OK || cls == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "FindClass status : %{public}d", status); + return nullptr; + } + ani_method ctor; + if ((status = env->Class_FindMethod(cls, "", "I:V", &ctor)) != ANI_OK || ctor == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "Class_FindMethod status : %{public}d", status); + return nullptr; + } + ani_object object; + if ((status = env->Object_New(cls, ctor, &object, value)) != ANI_OK || object == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "Object_New status : %{public}d", status); + return nullptr; + } + return object; +} + +bool SetOptionalFieldInt(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, int value) +{ + ani_field field = nullptr; + ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); + if (status != ANI_OK || field == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "Class_FindField failed or null field, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); + return false; + } + ani_object intObj = CreateInt(env, value); + if (intObj == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "null intObj"); + return false; + } + status = env->Object_SetField_Ref(object, field, intObj); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::JSNAPI, "Object_SetField_Ref failed, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); + return false; + } + return true; +} + bool AsyncCallback(ani_env *env, ani_object call, ani_object error, ani_object result) { if (env == nullptr) { diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 07098f4a8b379d2a2f90aeb7d00c17f140d1cac7..fd24c101b6e1dcb285cfc35ee6a8a1a58dc6d6f7 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -454,6 +454,23 @@ ohos_prebuilt_etc("ability_runtime_ability_stage_context_abc_etc") { deps = [ ":ability_runtime_ability_stage_context_abc" ] } +generate_static_abc("ability_runtime_ability_state_data_abc") { + base_url = "./" + files = [ "./application/AbilityStateData.ets" ] + + is_boot_abc = "True" + device_dst_file = + "/system/framework/ability_runtime_ability_state_data_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_ability_state_data_abc_etc") { + source = "$target_out_dir/ability_runtime_ability_state_data_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_ability_state_data_abc" ] +} + generate_static_abc("uri_permission_manager_abc") { base_url = "./" @@ -487,6 +504,7 @@ group("ets_packages") { ":ability_runtime_ability_result_abc_etc", ":ability_runtime_ability_stage_abc_etc", ":ability_runtime_ability_stage_context_abc_etc", + ":ability_runtime_ability_state_data_abc_etc", ":ability_runtime_ability_utils_abc_etc", ":ability_runtime_application_context_abc_etc", ":ability_runtime_base_context_abc_etc", diff --git a/frameworks/ets/ets/application/AbilityStateData.ets b/frameworks/ets/ets/application/AbilityStateData.ets new file mode 100644 index 0000000000000000000000000000000000000000..45f9d95e7f3eda243455cc0196943b51446da10f --- /dev/null +++ b/frameworks/ets/ets/application/AbilityStateData.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default class AbilityStateData { + readonly moduleName: string; + readonly bundleName: string; + readonly abilityName: string; + readonly pid: int; + readonly uid: int; + readonly state: int; + readonly abilityType: int; + readonly isAtomicService: boolean; + readonly appCloneIndex?: int; +} \ No newline at end of file diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 2ec7e98b9834b07575ea371a5b375b3a269364a3..f3567fdfed17b71867761260fbd9f81d65226a1f 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -174,6 +174,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/frameworks/ets/ani/ability_manager:ability_ability_manager_ani_kit", "${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_services_path}/common:app_util",