From 32be6642db1899ddd44ec1bba38aafbbef5550c8 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Fri, 1 Aug 2025 04:11:59 -0400 Subject: [PATCH 01/16] =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8D=95=E5=9B=9E?= =?UTF-8?q?=E5=90=880728?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzezhong --- .../src/ets_ability_manager_utils.cpp | 2 +- .../ani/ani_common/src/ani_common_util.cpp | 20 ++--- .../ani/app_manager/src/ets_app_manager.cpp | 61 +++++++++---- .../include/ets_ui_extension_context.h | 4 + .../src/ets_ui_extension.cpp | 6 +- .../src/ets_ui_extension_context.cpp | 89 +++++++++++++++++-- ...ohos.app.ability.ShareExtensionAbility.ets | 19 ++++ frameworks/ets/ets/BUILD.gn | 18 ++++ .../application/ApplicationStateObserver.ets | 6 +- .../ets/application/UIExtensionContext.ets | 10 +++ 10 files changed, 188 insertions(+), 47 deletions(-) create mode 100644 frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets diff --git a/frameworks/ets/ani/ability_manager/src/ets_ability_manager_utils.cpp b/frameworks/ets/ani/ability_manager/src/ets_ability_manager_utils.cpp index 035e645ea1d..8d585f896d7 100644 --- a/frameworks/ets/ani/ability_manager/src/ets_ability_manager_utils.cpp +++ b/frameworks/ets/ani/ability_manager/src/ets_ability_manager_utils.cpp @@ -38,7 +38,7 @@ bool WrapAbilityRunningInfoArray( return false; } ani_class arrayCls = nullptr; - ani_method arrayCtor; + ani_method arrayCtor = nullptr; ani_status status = ANI_ERROR; if ((status = env->FindClass(CLASSNAME_ARRAY, &arrayCls)) != ANI_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "status : %{public}d", status); 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 34eda52d4ae..1a76532c4db 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_util.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp @@ -245,18 +245,8 @@ bool SetFieldIntByName(ani_env *env, ani_class cls, ani_object object, const cha return false; } ani_status status = ANI_ERROR; - ani_field field = nullptr; - if ((status = env->Class_FindField(cls, name, &field)) != ANI_OK) { - TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); - return false; - } - ani_object obj = CreateInt(env, value); - if (obj == nullptr) { - TAG_LOGE(AAFwkTag::ANI, "obj is null"); - return false; - } - if ((status = env->Object_SetField_Ref(object, field, reinterpret_cast(obj))) != ANI_OK) { - TAG_LOGE(AAFwkTag::ANI, "status: %{public}d", status); + if ((status = env->Object_SetFieldByName_Int(object, name, value)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ANI, "Object_SetFieldByName_Int status: %{public}d", status); return false; } return true; @@ -869,9 +859,9 @@ bool SetProcessInformation(ani_env *env, ani_object object, const AppExecFwk::Ru TAG_LOGE(AAFwkTag::ANI, "bundleType failed status:%{public}d", status); return false; } - status = env->Object_SetPropertyByName_Ref(object, "appCloneIndex", - CreateInt(env, processInfo.appCloneIndex)); - if (status != ANI_OK) { + if (processInfo.appCloneIndex != -1 && + (status = env->Object_SetPropertyByName_Ref( + object, "appCloneIndex", CreateInt(env, processInfo.appCloneIndex))) != ANI_OK) { TAG_LOGE(AAFwkTag::ANI, "appCloneIndex failed status:%{public}d", status); return false; } diff --git a/frameworks/ets/ani/app_manager/src/ets_app_manager.cpp b/frameworks/ets/ani/app_manager/src/ets_app_manager.cpp index f4f9c5ea70e..3b5cfdb37f6 100644 --- a/frameworks/ets/ani/app_manager/src/ets_app_manager.cpp +++ b/frameworks/ets/ani/app_manager/src/ets_app_manager.cpp @@ -505,8 +505,9 @@ void EtsAppManager::OnOff(ani_env *env, ani_string type, ani_int etsObserverId, std::string strType; if (!AppExecFwk::GetStdString(env, type, strType) || strType != ON_OFF_TYPE) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError( - env, "Parse param type failed, must be a string, value must be applicationState."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param type failed, must be a string, value must be applicationState."), nullptr); return; } TAG_LOGD(AAFwkTag::APPMGR, "observerId:%{public}d", etsObserverId); @@ -523,12 +524,16 @@ void EtsAppManager::OnOff(ani_env *env, ani_string type, ani_int etsObserverId, } if (appStateObserver_ == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "null observer"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "observer is nullptr, please register first."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "observer is nullptr, please register first."), nullptr); return; } if (!appStateObserver_->FindObserverByObserverId(observerId)) { TAG_LOGE(AAFwkTag::APPMGR, "not find observer:%{public}d", static_cast(observerId)); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "not find observerId."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "not find observerId."), nullptr); return; } int32_t ret = appMgr->UnregisterApplicationStateObserver(appStateObserver_); @@ -654,7 +659,9 @@ void EtsAppManager::KillProcessesByBundleNameInner(ani_env *env, ani_object call std::string bundleName; if (!AppExecFwk::GetStdString(env, etsBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), nullptr); return; } int32_t appIndex = 0; @@ -663,7 +670,6 @@ void EtsAppManager::KillProcessesByBundleNameInner(ani_env *env, ani_object call TAG_LOGE(AAFwkTag::APPMGR, "Failed to check undefined status : %{public}d", status); return; } - if (!isUndefined) { if ((status = env->Object_CallMethodByName_Int(etsAppIndex, "toInt", nullptr, &appIndex)) != ANI_OK) { @@ -718,12 +724,12 @@ void EtsAppManager::KillProcessWithAccountInner(ani_env *env, ani_object callbac std::string bundleName; if (!AppExecFwk::GetStdString(env, aniBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), nullptr); return; } - TAG_LOGD(AAFwkTag::APPMGR, "KillProcessWithAccount accountId:%{public}d", aniAccountId); - int32_t appIndex = 0; ani_status status = ANI_OK; ani_boolean isUndefined = false; @@ -793,8 +799,9 @@ void EtsAppManager::GetRunningProcessInformationByBundleType( ani_int bundleType; if (!AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative(env, aniBundleType, bundleType)) { TAG_LOGE(AAFwkTag::APPMGR, "param aniBundleType err"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, - "Parse param bundleType failed, must be a BundleType."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleType failed, must be a BundleType."), emptyArray); return; } std::vector infos; @@ -841,7 +848,9 @@ void EtsAppManager::NativeIsSharedBundleRunning(ani_env *env, ani_string aniBund std::string bundleName; if (!AppExecFwk::GetStdString(env, aniBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), AppExecFwk::CreateBoolean(env, false)); return; } bool ret = appMgr->IsSharedBundleRunning(bundleName, versionCode); @@ -871,7 +880,9 @@ void EtsAppManager::NativeGetSupportedProcessCachePids(ani_env *env, ani_string std::string bundleName; if (!AppExecFwk::GetStdString(env, aniBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), emptyArray); return; } std::vector list; @@ -912,7 +923,9 @@ void EtsAppManager::NativeKillProcessesInBatch(ani_env *env, ani_object pids, an std::vector pidList; if (!UnWrapArrayInt(env, pids, pidList)) { TAG_LOGE(AAFwkTag::APPMGR, "Parse pids failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param pids failed, must be array of numbers."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param pids failed, must be array of numbers."), nullptr); return; } int32_t innerErrorCode = appMgr->GetAmsMgr()->KillProcessesInBatch(pidList); @@ -942,7 +955,9 @@ void EtsAppManager::NativeIsAppRunning(ani_env *env, ani_object callback, ani_st std::string bundleName; if (!AppExecFwk::GetStdString(env, aniBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), AppExecFwk::CreateBoolean(env, false)); return; } ani_status status = ANI_OK; @@ -986,13 +1001,17 @@ void EtsAppManager::NativeSetKeepAliveForBundle(ani_env *env, ani_string aniBund auto abilityManager = GetAbilityManagerInstance(); if (abilityManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "abilityManager null ptr"); - AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateError( + env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER), nullptr); return; } std::string bundleName; if (!AppExecFwk::GetStdString(env, aniBundleName, bundleName)) { TAG_LOGE(AAFwkTag::APPMGR, "GetStdString Failed"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param bundleName failed, must be a string."), nullptr); return; } TAG_LOGD(AAFwkTag::APPMGR, "KillProcessWithAccount aniUserId:%{public}d", aniUserId); @@ -1015,13 +1034,17 @@ void EtsAppManager::NativeGetKeepAliveBundles(ani_env *env, ani_object callback, auto abilityManager = GetAbilityManagerInstance(); if (abilityManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "abilityManager null ptr"); - AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateError( + env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER), nullptr); return; } ani_int appType = 0; if (!AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative(env, aniType, appType)) { TAG_LOGE(AAFwkTag::APPMGR, "param mode err"); - AbilityRuntime::EtsErrorUtil::ThrowInvalidParamError(env, "Parse param appType failed, must be a number."); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateInvalidParamError( + env, "Parse param appType failed, must be a number."), nullptr); return; } ani_status status = ANI_OK; diff --git a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h index c1252a34b93..4df327ef93b 100644 --- a/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h +++ b/frameworks/ets/ani/ui_extension_ability/include/ets_ui_extension_context.h @@ -71,6 +71,8 @@ public: static void StartAbilityForResult(ani_env *env, ani_object aniObj, ani_object wantObj, ani_object callback); static void StartAbilityForResultWithOptions(ani_env *env, ani_object aniObj, ani_object wantObj, ani_object startOptionsObj, ani_object callback); + static void SetColorMode(ani_env *env, ani_object aniObj, ani_enum_item aniColorMode); + static void ReportDrawnCompleted(ani_env *env, ani_object aniObj, ani_object callback); static bool BindNativePtrCleaner(ani_env *env); static void Clean(ani_env *env, ani_object object); @@ -89,6 +91,8 @@ private: ani_object callback); static bool CheckConnectionParam(ani_env *env, ani_object connectOptionsObj, sptr& connection, AAFwk::Want& want); + void OnSetColorMode(ani_env *env, ani_object aniCls, ani_enum_item aniColorMode); + void OnReportDrawnCompleted(ani_env *env, ani_object aniCls, ani_object callback); protected: std::weak_ptr context_; diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp index e49bc810f7f..58157cb3f78 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension.cpp @@ -198,18 +198,18 @@ void EtsUIExtension::BindContext(ani_env *env, std::shared_ptr want ani_field contextField = nullptr; auto status = env->Class_FindField(etsObj_->aniCls, "context", &contextField); if (status != ANI_OK) { - TAG_LOGE(AAFwkTag::ETSRUNTIME, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); return; } ani_ref contextRef = nullptr; if ((status = env->GlobalReference_Create(contextObj, &contextRef)) != ANI_OK) { - TAG_LOGE(AAFwkTag::ETSRUNTIME, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); return; } if ((status = env->Object_SetField_Ref(etsObj_->aniObj, contextField, contextRef)) != ANI_OK) { - TAG_LOGE(AAFwkTag::ETSRUNTIME, "status: %{public}d", status); + TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); } shellContextRef_ = std::make_shared(); shellContextRef_->aniObj = contextObj; diff --git a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp index 3b5051a2483..59228da3ffe 100644 --- a/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp +++ b/frameworks/ets/ani/ui_extension_ability/src/ets_ui_extension_context.cpp @@ -19,6 +19,7 @@ #include "ani_common_start_options.h" #include "ani_common_remote.h" #include "ani_common_want.h" +#include "ani_enum_convert.h" #include "ani_remote_object.h" #include "common_fun_ani.h" #include "ets_context_utils.h" @@ -291,7 +292,7 @@ void EtsUIExtensionContext::OnStartAbilityForResult(ani_env *env, ani_object ani if (startOptionsObj) { OHOS::AppExecFwk::UnwrapStartOptions(env, startOptionsObj, startOptions); } - + ani_ref callbackRef = nullptr; env->GlobalReference_Create(callback, &callbackRef); ani_vm *etsVm = nullptr; @@ -309,7 +310,7 @@ void EtsUIExtensionContext::OnStartAbilityForResult(ani_env *env, ani_object ani TAG_LOGE(AAFwkTag::UI_EXT, "GetEnv failed, status: %{public}d", status); return; } - + ani_object abilityResult = AppExecFwk::WrapAbilityResult(env, resultCode, want); if (abilityResult == nullptr) { TAG_LOGW(AAFwkTag::UI_EXT, "null abilityResult"); @@ -400,7 +401,6 @@ void EtsUIExtensionContext::OnDisconnectServiceExtensionAbility(ani_env *env, an g_connects.erase(item); } else { TAG_LOGI(AAFwkTag::UI_EXT, "Failed to found connection"); - return; } } if (!connection) { @@ -499,6 +499,71 @@ void EtsUIExtensionContext::Clean(ani_env *env, ani_object object) } } +void EtsUIExtensionContext::SetColorMode(ani_env *env, ani_object aniObj, ani_enum_item aniColorMode) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "SetColorMode called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null env"); + return; + } + auto etsUiExtensionContext = GetEtsUIExtensionContext(env, aniObj); + if (etsUiExtensionContext == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null etsUiExtensionContext"); + return; + } + etsUiExtensionContext->OnSetColorMode(env, aniObj, aniColorMode); +} + +void EtsUIExtensionContext::ReportDrawnCompleted(ani_env *env, ani_object aniObj, ani_object callback) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "ReportDrawnCompleted called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null env"); + return; + } + auto etsUiExtensionContext = GetEtsUIExtensionContext(env, aniObj); + if (etsUiExtensionContext == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null etsUiExtensionContext"); + return; + } + etsUiExtensionContext->OnReportDrawnCompleted(env, aniObj, callback); +} + +void EtsUIExtensionContext::OnSetColorMode(ani_env *env, ani_object aniContext, ani_enum_item aniColorMode) +{ + auto context = context_.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null context"); + EtsErrorUtil::ThrowError(env, static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); + return; + } + ani_int colorMode = 0; + if (!AAFwk::AniEnumConvertUtil::EnumConvert_EtsToNative(env, aniColorMode, colorMode)) { + TAG_LOGE(AAFwkTag::UI_EXT, "param aniColorMode err"); + EtsErrorUtil::ThrowInvalidParamError(env, "Parse param colorMode failed, colorMode must be number."); + return; + } + context->SetAbilityColorMode(colorMode); + TAG_LOGD(AAFwkTag::UI_EXT, "NativeSetColorMode end"); +} + +void EtsUIExtensionContext::OnReportDrawnCompleted(ani_env* env, ani_object aniCls, ani_object callback) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "OnReportDrawnCompleted called"); + auto context = context_.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null context"); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)), nullptr); + return; + } + int32_t innerErrorCode = context->ReportDrawnCompleted(); + AppExecFwk::AsyncCallback(env, callback, AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, + static_cast(innerErrorCode)), nullptr); + TAG_LOGD(AAFwkTag::UI_EXT, "NativeReportDrawnCompleted end"); +} + bool EtsUIExtensionContext::BindNativePtrCleaner(ani_env *env) { if (env == nullptr) { @@ -564,17 +629,31 @@ ani_object CreateEtsUIExtensionContext(ani_env *env, std::shared_ptr(EtsUIExtensionContext::StartAbilityForResultWithOptions) }, + ani_native_function{"setColorMode", + "L@ohos/app/ability/ConfigurationConstant/ConfigurationConstant/ColorMode;:V", + reinterpret_cast(EtsUIExtensionContext::SetColorMode)}, + ani_native_function{"nativeReportDrawnCompleted", + "Lutils/AbilityUtils/AsyncCallbackWrapper;:V", + reinterpret_cast(EtsUIExtensionContext::ReportDrawnCompleted)} }; if ((status = env->Class_BindNativeMethods(cls, functions.data(), functions.size())) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); return nullptr; } - if ((status = env->Object_SetFieldByName_Long(contextObj, "nativeContext", (ani_long)context.get())) != ANI_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); + auto workContext = new (std::nothrow) + std::weak_ptr(context); + if (workContext == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null workContext"); + return nullptr; + } + if (!ContextUtil::SetNativeContextLong(env, contextObj, (ani_long)workContext)) { + TAG_LOGE(AAFwkTag::UI_EXT, "SetNativeContextLong failed"); + delete workContext; return nullptr; } if (!EtsUIExtensionContext::BindNativePtrCleaner(env)) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); + delete workContext; return nullptr; } OHOS::AbilityRuntime::ContextUtil::CreateEtsBaseContext(env, cls, contextObj, context); diff --git a/frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets b/frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets new file mode 100644 index 00000000000..b238c15ea6a --- /dev/null +++ b/frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets @@ -0,0 +1,19 @@ +/* + * 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; + +export default class ShareExtensionAbility extends UIExtensionAbility { +} \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index efa1a659ad3..6d456a2a881 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -1192,6 +1192,22 @@ ohos_prebuilt_etc("ability_runtime_event_hub_abc_etc") { deps = [ ":ability_runtime_event_hub_abc" ] } +generate_static_abc("ability_runtime_share_extension_ability_abc") { + base_url = "./" + files = [ "./@ohos.app.ability.ShareExtensionAbility.ets" ] + + is_boot_abc = "True" + device_dst_file = + "/system/framework/ability_runtime_share_extension_ability_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_share_extension_ability_abc_etc") { + source = "$target_out_dir/ability_runtime_share_extension_ability_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_share_extension_ability_abc" ] +} group("ets_packages") { deps = [ @@ -1244,6 +1260,7 @@ group("ets_packages") { ":ability_runtime_insight_intent_executor_abc_etc", ":ability_runtime_mission_info_abc_etc", ":ability_runtime_openLink_options_abc_etc", + ":ability_runtime_share_extension_ability_abc_etc", ":ability_runtime_shell_cmd_result_abc_etc", ":ability_runtime_start_options_abc_etc", ":ability_runtime_trigger_info_abc_etc", @@ -1260,6 +1277,7 @@ group("ets_packages") { ":ability_runtime_want_constant_abc_etc", ":atomic_service_options_abc_etc", ":application_state_observer_abc_etc", + ":app_foreground_state_observer_abc_etc", ":form_extension_ability_etc", ":service_extension_ability_abc_etc", ":ui_extension_ability_ani_etc", diff --git a/frameworks/ets/ets/application/ApplicationStateObserver.ets b/frameworks/ets/ets/application/ApplicationStateObserver.ets index 3b59dc77f22..e67cae97100 100644 --- a/frameworks/ets/ets/application/ApplicationStateObserver.ets +++ b/frameworks/ets/ets/application/ApplicationStateObserver.ets @@ -16,7 +16,7 @@ import AppStateData from 'application.AppStateData'; import AbilityStateData from 'application.AbilityStateData'; import processData from 'application.ProcessData'; -interface ApplicationStateObserver { +export interface ApplicationStateObserver { onForegroundApplicationChanged(appStateData: AppStateData): void; @@ -33,7 +33,7 @@ interface ApplicationStateObserver { onAppStopped(appStateData: AppStateData): void; } -class ApplicationStateObserverImpl implements ApplicationStateObserver { +export default class ApplicationStateObserverImpl implements ApplicationStateObserver { onForegroundApplicationChanged(appStateData: AppStateData): void {} onAbilityStateChanged(abilityStateData: AbilityStateData): void {} @@ -50,5 +50,3 @@ class ApplicationStateObserverImpl implements ApplicationStateObserver { } export type ProcessData = processData; - -export default ApplicationStateObserver; \ No newline at end of file diff --git a/frameworks/ets/ets/application/UIExtensionContext.ets b/frameworks/ets/ets/application/UIExtensionContext.ets index 79037510d55..b7fb7e061ed 100644 --- a/frameworks/ets/ets/application/UIExtensionContext.ets +++ b/frameworks/ets/ets/application/UIExtensionContext.ets @@ -21,6 +21,7 @@ import AsyncCallbackWrapper from '../utils/AbilityUtils'; import ExtensionContext from 'application.ExtensionContext'; import StartOptions from '@ohos.app.ability.StartOptions'; import Want from '@ohos.app.ability.Want'; +import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; class Cleaner { static callback(cleaner: Cleaner): void { @@ -61,6 +62,8 @@ export default class UIExtensionContext extends ExtensionContext { private native nativeStartAbilityForResult(want: Want, callback:AsyncCallbackWrapper): void; private native nativeStartAbilityForResult(want: Want, startOptions: StartOptions, callback:AsyncCallbackWrapper): void; + native setColorMode(colorMode: ConfigurationConstant.ColorMode): void; + native nativeReportDrawnCompleted(callback:AsyncCallbackWrapper): void; terminateSelf(callback:AsyncCallback): void { let myCall = new AsyncCallbackWrapper(callback); @@ -212,4 +215,11 @@ export default class UIExtensionContext extends ExtensionContext { }); return p; } + + reportDrawnCompleted(callback: AsyncCallback): void { + let myCall = new AsyncCallbackWrapper(callback); + taskpool.execute((): void => { + this.nativeReportDrawnCompleted(myCall); + }); + } } \ No newline at end of file -- Gitee From d5b3da59da5260469c1c98e0ccb1e90887840871 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Sat, 2 Aug 2025 16:58:45 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang_hao_zheng Change-Id: I220b60f919fac8bec2d93dd0e6bb1e3a523cc0ce --- services/appmgr/src/app_mgr_service_inner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 094865db94b..04856f7ea15 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -4209,7 +4209,8 @@ int32_t AppMgrServiceInner::StartProcess(const std::string &appName, const std:: } SendCreateAtomicServiceProcessEvent(appRecord, bundleType, moduleName, abilityName); errCode = remoteClientManager_->GetCJSpawnClient()->StartProcess(startMsg, pid); - } else if (appInfo->arkTSMode == CODE_LANGUAGE_ARKTS_1_2 || appInfo->arkTSMode == CODE_LANGUAGE_ARKTS_HYBRID) { + } else if (appInfo != nullptr && + (appInfo->arkTSMode == CODE_LANGUAGE_ARKTS_1_2 || appInfo->arkTSMode == CODE_LANGUAGE_ARKTS_HYBRID)) { SendCreateAtomicServiceProcessEvent(appRecord, bundleType, moduleName, abilityName); startMsg.gids.push_back(SHADER_CACHE_GROUPID); errCode = remoteClientManager_->GetHybridSpawnClient()->StartProcess(startMsg, pid); -- Gitee From 8edacdfca94a951d25f868aac28b3906c47c59a9 Mon Sep 17 00:00:00 2001 From: 30059993 Date: Mon, 21 Jul 2025 15:16:32 +0800 Subject: [PATCH 03/16] suport 1_2 hsp Signed-off-by: 30059993 --- .../frameworks/ets_environment/BUILD.gn | 3 + .../ets_environment/src/ets_environment.cpp | 196 ++++++++++++++++-- .../interfaces/inner_api/ets_environment.h | 10 +- .../interfaces/inner_api/ets_interface.h | 7 +- frameworks/native/appkit/app/main_thread.cpp | 8 + frameworks/native/runtime/ets_runtime.cpp | 5 +- .../inner_api/runtime/include/runtime.h | 8 + .../multi_user_config_mgr_test.cpp | 14 +- test/unittest/runtime_test/BUILD.gn | 1 + 9 files changed, 235 insertions(+), 17 deletions(-) diff --git a/ets_environment/frameworks/ets_environment/BUILD.gn b/ets_environment/frameworks/ets_environment/BUILD.gn index 1c67d800122..8bc85903f65 100644 --- a/ets_environment/frameworks/ets_environment/BUILD.gn +++ b/ets_environment/frameworks/ets_environment/BUILD.gn @@ -48,9 +48,12 @@ ohos_shared_library("ets_environment") { deps = [ "${ability_runtime_innerkits_path}/connect_server_manager:connect_server_manager", + "${ability_runtime_innerkits_path}/runtime:runtime", ] external_deps = [ + "ability_base:string_utils", + "bundle_framework:appexecfwk_base", "c_utils:utils", "eventhandler:libeventhandler", "faultloggerd:libunwinder", diff --git a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp index f08d9859391..4b4f96d79ac 100644 --- a/ets_environment/frameworks/ets_environment/src/ets_environment.cpp +++ b/ets_environment/frameworks/ets_environment/src/ets_environment.cpp @@ -24,6 +24,10 @@ #include #include +#include "bundle_constants.h" +#include "constants.h" +#include "file_path_utils.h" +#include "runtime.h" #include "static_core/plugins/ets/runtime/ets_namespace_manager.h" #include "static_core/runtime/tooling/inspector/debugger_arkapi.h" #include "ets_ani_expo.h" @@ -439,18 +443,24 @@ bool ETSEnvironment::LoadAbcLinker(ani_env *env, const std::string &modulePath, TAG_LOGE(AAFwkTag::ETSRUNTIME, "FindClass failed, status: %{public}d", status); return false; } - ani_method method = nullptr; - if ((status = env->Class_FindMethod(abcCls, "", "Lstd/core/RuntimeLinker;[Lstd/core/String;:V", - &method)) != ANI_OK) { - TAG_LOGE(AAFwkTag::ETSRUNTIME, "Class_FindMethod failed, status: %{public}d", status); + + abcObj = CreateRuntimeLinker(env, abcCls, undefinedRef, refArray); + if (abcObj == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "CreateRuntimeLinker failed"); return false; } - env->ResetError(); - if ((status = env->Object_New(abcCls, method, &abcObj, undefinedRef, refArray)) != ANI_OK) { - TAG_LOGE(AAFwkTag::ETSRUNTIME, "Object_New failed, status: %{public}d", status); - HandleUncaughtError(); + + ani_class contextCls{}; + if ((status = env->FindClass("std.interop.InteropContext", &contextCls)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "InteropContext failed, status: %{public}d", status); return false; } + if ((status = env->Class_CallStaticMethodByName_Void( + contextCls, "setDefaultInteropLinker", "C{std.core.RuntimeLinker}:", abcObj)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "setDefaultInteropLinker failed, status: %{public}d", status); + return false; + } + return true; } @@ -516,7 +526,9 @@ void ETSEnvironment::FinishPreload() { ark::ets::ETSAni::Prefork(env); } -void ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath) +void ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath, + const std::vector &appInnerHspPathList, + const std::vector &commonHspBundleInfos) { std::vector options; std::string aotPathString = ""; @@ -535,6 +547,8 @@ void ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath) return; } ark::ets::ETSAni::Postfork(env, options); + appInnerHspPathList_ = appInnerHspPathList; + commonHspBundleInfos_ = commonHspBundleInfos; } void ETSEnvironment::PreloadSystemClass(const char *className) @@ -584,8 +598,9 @@ ETSEnvFuncs *ETSEnvironment::RegisterFuncs() .FinishPreload = []() { ETSEnvironment::GetInstance()->FinishPreload(); }, - .PostFork = [](void *napiEnv, const std::string &aotPath) { - ETSEnvironment::GetInstance()->PostFork(napiEnv, aotPath); + .PostFork = [](void *napiEnv, const std::string &aotPath, const std::vector &appInnerHspPathList, + const std::vector &commonHspBundleInfos) { + ETSEnvironment::GetInstance()->PostFork(napiEnv, aotPath, appInnerHspPathList, commonHspBundleInfos); }, .PreloadSystemClass = [](const char *className) { ETSEnvironment::GetInstance()->PreloadSystemClass(className); @@ -697,10 +712,167 @@ void ETSEnvironment::BroadcastAndConnect(const std::string& bundleName, int sock AbilityRuntime::ConnectServerManager::Get().SendInstanceMessageAll(nullptr); AbilityRuntime::ConnectServerManager::Get().StartConnectServer(bundleName, socketFd, false); } + +bool ETSEnvironment::ConvertHspPathToAniArray(ani_env *aniEnv, const std::vector &hapPathInfos, + ani_array_ref &refArray) +{ + if (aniEnv == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "GetAniEnv failed"); + return false; + } + ani_status status = ANI_ERROR; + ani_class stringCls = nullptr; + if ((status = aniEnv->FindClass(CLASSNAME_STRING, &stringCls)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "FindClass Lstd/core/String Failed, status: %{public}d", status); + return false; + } + + ani_ref undefined_ref; + if ((status = aniEnv->GetUndefined(&undefined_ref)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "GetUndefined failed, status: %{public}d", status); + return false; + } + + if ((status = aniEnv->Array_New_Ref(stringCls, hapPathInfos.size(), undefined_ref, &refArray)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Array_New_Ref Failed, status: %{public}d", status); + return false; + } + + for (size_t index = 0; index < hapPathInfos.size(); index++) { + std::string hspPath = hapPathInfos[index]; + ani_string ani_str; + if ((status = aniEnv->String_NewUTF8(hspPath.c_str(), hspPath.size(), &ani_str)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "String_NewUTF8 modulePath Failed, status: %{public}d", status); + return false; + } + if ((status = aniEnv->Array_Set_Ref(refArray, index, ani_str)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Array_Set_Ref Failed, status: %{public}d", status); + return false; + } + } + return true; +} + +std::vector ETSEnvironment::GetHspPathList() +{ + std::vector hspPathList; + for (const auto &bundleInfo : commonHspBundleInfos_) { + if (bundleInfo.moduleArkTSMode == AppExecFwk::Constants::ARKTS_MODE_DYNAMIC) { + continue; + } + auto pos = bundleInfo.hapPath.rfind('/'); + if (pos == std::string::npos) { + TAG_LOGW(AAFwkTag::ETSRUNTIME, "hapPath invalid:%{public}s", bundleInfo.hapPath.c_str()); + continue; + } + std::string hspName = bundleInfo.hapPath.substr(pos); + hspPathList.push_back(std::string(AbilityBase::Constants::LOCAL_CODE_PATH) + + std::string(AbilityBase::Constants::FILE_SEPARATOR) + bundleInfo.bundleName + + std::string(AbilityBase::Constants::FILE_SEPARATOR) + bundleInfo.moduleName + hspName); + } + + for (const auto &appInnerHspPath : appInnerHspPathList_) { + hspPathList.push_back(AbilityBase::GetLoadPath(appInnerHspPath)); + } + + for (const auto &it : hspPathList) { + TAG_LOGD(AAFwkTag::ETSRUNTIME, "list hspPath:%{public}s", it.c_str()); + } + + return hspPathList; +} + +bool ETSEnvironment::GetHspAbcRuntimeLinker(ani_array_ref &refHspLinkerArray, ani_class cls) +{ + const auto &hspPathList = GetHspPathList(); + if (hspPathList.empty()) { + return true; + } + ani_env *aniEnv = GetAniEnv(); + if (aniEnv == nullptr) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "GetAniEnv failed"); + return false; + } + ani_status status = ANI_ERROR; + ani_method method = nullptr; + if ((status = aniEnv->Class_FindMethod(cls, "", "Lstd/core/RuntimeLinker;Lescompat/Array;:V", + &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Class_FindMethod ctor failed, status: %{public}d", status); + return false; + } + + ani_ref undefined_ref; + if ((status = aniEnv->GetUndefined(&undefined_ref)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "GetUndefined failed, status: %{public}d", status); + return false; + } + + ani_array_ref str_refArray; + if (ConvertHspPathToAniArray(aniEnv, hspPathList, str_refArray) == false) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "ConvertHspPathToAniArray failed"); + return false; + } + + ani_object object = nullptr; + if ((status = aniEnv->Object_New(cls, method, &object, undefined_ref, str_refArray)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Object_New AbcRuntimeLinker failed, status: %{public}d", status); + return false; + } + + if ((status = aniEnv->Array_New_Ref(cls, 1, undefined_ref, &refHspLinkerArray)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Array_New_Ref Failed, status: %{public}d", status); + return false; + } + if ((status = aniEnv->Array_Set_Ref(refHspLinkerArray, 0, object)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Array_Set_Ref Failed, status: %{public}d", status); + return false; + } + return true; +} + +ani_object ETSEnvironment::CreateRuntimeLinker( + ani_env *aniEnv, ani_class cls, ani_ref undefined_ref, ani_array_ref& refArray) +{ + ani_object object = nullptr; + ani_array_ref refHspLinkerArray = nullptr; + GetHspAbcRuntimeLinker(refHspLinkerArray, cls); + ani_status status = ANI_ERROR; + + if (refHspLinkerArray == nullptr) { + ani_method runtimeLinkerCtorMethod = nullptr; + if ((status = aniEnv->Class_FindMethod( + cls, "", "Lstd/core/RuntimeLinker;Lescompat/Array;:V", &runtimeLinkerCtorMethod)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Class_FindMethod ctor failed, status: %{public}d", status); + return nullptr; + } + if ((status = aniEnv->Object_New(cls, runtimeLinkerCtorMethod, &object, undefined_ref, refArray)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Object_New runtimeLinkerCtorMethod failed, status: %{public}d", status); + HandleUncaughtError(); + return nullptr; + } + } else { + ani_method runtimeLinkerCtorMethodEx = nullptr; + if ((status = aniEnv->Class_FindMethod(cls, + "", + "Lstd/core/RuntimeLinker;Lescompat/Array;[Lstd/core/RuntimeLinker;:V", + &runtimeLinkerCtorMethodEx)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Class_FindMethod ctor failed, status: %{public}d", status); + return nullptr; + } + if ((status = aniEnv->Object_New(cls, runtimeLinkerCtorMethodEx, &object, undefined_ref, refArray, + refHspLinkerArray)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Object_New runtimeLinkerCtorMethodEx failed, status: %{public}d", status); + HandleUncaughtError(); + return nullptr; + } + } + + return object; +} } // namespace EtsEnv } // namespace OHOS ETS_EXPORT extern "C" ETSEnvFuncs *OHOS_ETS_ENV_RegisterFuncs() { return OHOS::EtsEnv::ETSEnvironment::RegisterFuncs(); -} \ No newline at end of file +} diff --git a/ets_environment/interfaces/inner_api/ets_environment.h b/ets_environment/interfaces/inner_api/ets_environment.h index c7a79c5f570..2e9a19aea07 100644 --- a/ets_environment/interfaces/inner_api/ets_environment.h +++ b/ets_environment/interfaces/inner_api/ets_environment.h @@ -60,7 +60,8 @@ public: bool LoadModule(const std::string &modulePath, const std::string &srcEntrance, void *&cls, void *&obj, void *&ref); void FinishPreload(); - void PostFork(void *napiEnv, const std::string &aotPath); + void PostFork(void *napiEnv, const std::string &aotPath, const std::vector& appInnerHspPathList, + const std::vector &commonHspBundleInfos); void PreloadSystemClass(const char *className); void RemoveInstance(uint32_t instanceId); @@ -83,6 +84,11 @@ public: }; private: + bool ConvertHspPathToAniArray(ani_env *aniEnv, const std::vector &hapPathInfos, + ani_array_ref &refArray); + std::vector GetHspPathList(); + bool GetHspAbcRuntimeLinker(ani_array_ref &refHspLinkerArray, ani_class cls); + ani_object CreateRuntimeLinker(ani_env *aniEnv, ani_class cls, ani_ref undefined_ref, ani_array_ref &refArray); bool LoadRuntimeApis(); bool LoadSymbolCreateVM(void *handle, ETSRuntimeAPI &apis); bool LoadSymbolANIGetCreatedVMs(void *handle, ETSRuntimeAPI &apis); @@ -98,6 +104,8 @@ private: ETSUncaughtExceptionInfo uncaughtExceptionInfo_; std::shared_ptr eventHandler_; bool debugMode_ = false; + std::vector appInnerHspPathList_; + std::vector commonHspBundleInfos_; }; } // namespace EtsEnv } // namespace OHOS diff --git a/ets_environment/interfaces/inner_api/ets_interface.h b/ets_environment/interfaces/inner_api/ets_interface.h index fa6fcc369d2..935a46ef708 100644 --- a/ets_environment/interfaces/inner_api/ets_interface.h +++ b/ets_environment/interfaces/inner_api/ets_interface.h @@ -27,6 +27,9 @@ namespace OHOS { namespace AppExecFwk { class EventRunner; } +namespace AbilityRuntime { + struct CommonHspBundleInfo; +} } extern "C" { @@ -45,7 +48,9 @@ struct ETSEnvFuncs { void (*SetAppLibPath)(const std::map &abcPathsToBundleModuleNameMap, std::function &cb) = nullptr; void (*FinishPreload)() = nullptr; - void (*PostFork)(void *napiEnv, const std::string &aotPath) = nullptr; + void (*PostFork)(void *napiEnv, const std::string &aotPath, + const std::vector &appInnerHspPathList, + const std::vector &commonHspBundleInfos) = nullptr; void (*PreloadSystemClass)(const char *className) = nullptr; void (*RemoveInstance)(uint32_t instanceId) = nullptr; void (*StopDebugMode)(void *jsVm) = nullptr; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index e5ceb9110c4..545d5c42098 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1713,10 +1713,18 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { options.hapModulePath[hapModuleInfo.moduleName] = hapModuleInfo.hapPath; options.packageNameList[hapModuleInfo.moduleName] = hapModuleInfo.packageName; + if (hapModuleInfo.moduleType == AppExecFwk::ModuleType::SHARED && + hapModuleInfo.moduleArkTSMode != AppExecFwk::Constants::ARKTS_MODE_DYNAMIC) { + TAG_LOGD(AAFwkTag::APPKIT, "appInnerHspPathList: %{public}s", hapModuleInfo.hapPath.c_str()); + options.appInnerHspPathList.push_back(hapModuleInfo.hapPath); + } options.aotCompileStatusMap[hapModuleInfo.moduleName] = static_cast(hapModuleInfo.aotCompileStatus); } } + for (const auto &hsp : hspList) { + options.commonHspBundleInfos.push_back({hsp.bundleName, hsp.moduleName, hsp.hapPath, hsp.moduleArkTSMode}); + } options.enableWarmStartupSmartGC = (appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRE_MAKE || appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRELOAD_MODULE); diff --git a/frameworks/native/runtime/ets_runtime.cpp b/frameworks/native/runtime/ets_runtime.cpp index e5c0886feaa..98ed7221404 100644 --- a/frameworks/native/runtime/ets_runtime.cpp +++ b/frameworks/native/runtime/ets_runtime.cpp @@ -278,7 +278,8 @@ void ETSRuntime::PostFork(const Options &options, std::unique_ptr &js aotFilePath = SANDBOX_ARK_CACHE_PATH + options.arkNativeFilePath + options.moduleName + ".an"; } napi_env napiEnv = static_cast(jsRuntime_.get())->GetNapiEnv(); - g_etsEnvFuncs->PostFork(reinterpret_cast(napiEnv), aotFilePath); + g_etsEnvFuncs->PostFork(reinterpret_cast(napiEnv), aotFilePath, options.appInnerHspPathList, + options.commonHspBundleInfos); } std::unique_ptr ETSRuntime::Create(const Options &options, std::unique_ptr &jsRuntime) @@ -699,4 +700,4 @@ void ETSRuntime::StopDebugMode() g_etsEnvFuncs->StopDebugMode(vm); } } // namespace AbilityRuntime -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 0a0bd6ebd28..721d67dd6e2 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -27,6 +27,12 @@ namespace AppExecFwk { class EventRunner; } // namespace AppExecFwk namespace AbilityRuntime { +struct CommonHspBundleInfo { + std::string bundleName; + std::string moduleName; + std::string hapPath; + std::string moduleArkTSMode; +}; namespace { const std::string CODE_LANGUAGE_ARKTS_1_0 = "dynamic"; const std::string CODE_LANGUAGE_ARKTS_1_2 = "static"; @@ -55,6 +61,8 @@ public: std::vector assetBasePathStr; std::shared_ptr eventRunner = nullptr; std::map hapModulePath; + std::vector appInnerHspPathList; + std::vector commonHspBundleInfos; bool loadAce = true; bool preload = false; bool isBundle = true; diff --git a/test/unittest/multi_user_config_mgr_test/multi_user_config_mgr_test.cpp b/test/unittest/multi_user_config_mgr_test/multi_user_config_mgr_test.cpp index 8c9c1a0363b..093ecb4fc16 100644 --- a/test/unittest/multi_user_config_mgr_test/multi_user_config_mgr_test.cpp +++ b/test/unittest/multi_user_config_mgr_test/multi_user_config_mgr_test.cpp @@ -308,6 +308,19 @@ HWTEST_F(MultiUserConfigMgrTest, GetConfigurationByUserId_0100, TestSize.Level1) EXPECT_NE(multiUserConfigurationMgr->GetConfigurationByUserId(userId), nullptr); } +/** +* @tc.name: GetConfigurationByUserId_0300 +* @tc.desc: GetConfigurationByUserId. +* @tc.type: FUNC +*/ +HWTEST_F(MultiUserConfigMgrTest, GetConfigurationByUserId_0300, TestSize.Level1) +{ + auto multiUserConfigurationMgr = + std::make_shared(); + multiUserConfigurationMgr->globalConfiguration_ = nullptr; + EXPECT_EQ(multiUserConfigurationMgr->GetConfigurationByUserId(100), nullptr); +} + /** * @tc.name: GetConfigurationByUserId_0400 * @tc.desc: GetConfigurationByUserId. @@ -319,6 +332,5 @@ HWTEST_F(MultiUserConfigMgrTest, GetConfigurationByUserId_0400, TestSize.Level1) multiUserConfigurationMgr->globalConfiguration_ = std::make_shared(); EXPECT_NE(multiUserConfigurationMgr->GetConfigurationByUserId(100), nullptr); } - } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/runtime_test/BUILD.gn b/test/unittest/runtime_test/BUILD.gn index 709cca19846..07f8a6615e3 100644 --- a/test/unittest/runtime_test/BUILD.gn +++ b/test/unittest/runtime_test/BUILD.gn @@ -289,6 +289,7 @@ ohos_unittest("ets_runtime_test") { ] external_deps = [ + "ability_base:string_utils", "ability_runtime:runtime", "bundle_framework:appexecfwk_core", "c_utils:utils", -- Gitee From 275ff4258ffc92f07b8637e694e5ba81ba1852c3 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:22:31 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E6=8C=91=E5=8D=950728=2015786?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang_hao_zheng Change-Id: I5be96d84220b453ac961a81a508e402a6661cbe2 --- frameworks/ets/ani/ani_common/src/ets_context_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp index 481a88af279..b1f0fcc519a 100644 --- a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp @@ -141,7 +141,7 @@ void Clean(ani_env *env, ani_object object) return; } if (ptr != 0) { - delete reinterpret_cast(ptr); + delete reinterpret_cast *>(ptr); } } -- Gitee From b7055da96e6abebaebb3678084122378bccd9b6f Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:40:02 +0800 Subject: [PATCH 05/16] merge 15715&15750 Signed-off-by: zhang_hao_zheng Change-Id: Ifb935545b92c000e925ec53f7eb30622463bf515 --- .../ets_application_state_change_callback.h | 9 +- .../include/ets_enviroment_callback.h | 9 +- .../src/ets_application_context_utils.cpp | 15 ++- .../ets_application_state_change_callback.cpp | 90 ++++++++++--- .../src/ets_enviroment_callback.cpp | 119 +++++++++++++++--- .../ets/ani/wantagent/src/ani_want_agent.cpp | 26 ++-- .../ets/ets/wantAgent/wantAgentInfo.ets | 4 - 7 files changed, 212 insertions(+), 60 deletions(-) diff --git a/frameworks/ets/ani/ani_common/include/ets_application_state_change_callback.h b/frameworks/ets/ani/ani_common/include/ets_application_state_change_callback.h index 989e30bf748..07270a2e373 100644 --- a/frameworks/ets/ani/ani_common/include/ets_application_state_change_callback.h +++ b/frameworks/ets/ani/ani_common/include/ets_application_state_change_callback.h @@ -29,8 +29,8 @@ namespace AbilityRuntime { class EtsApplicationStateChangeCallback : public ApplicationStateChangeCallback, public std::enable_shared_from_this { public: - explicit EtsApplicationStateChangeCallback(ani_env *env); - virtual ~EtsApplicationStateChangeCallback() = default; + explicit EtsApplicationStateChangeCallback(ani_vm *etsVm); + ~EtsApplicationStateChangeCallback() override; void NotifyApplicationForeground() override; void NotifyApplicationBackground() override; void Register(ani_object aniCallback); @@ -43,11 +43,14 @@ public: */ bool UnRegister(ani_object aniCallback = nullptr); bool IsEmpty() const; + ani_env *AttachCurrentThread(); + void DetachCurrentThread(); private: void CallEtsMethod(const std::string &methodName); - ani_env *env_ = nullptr; + ani_vm *etsVm_ = nullptr; std::set callbacks_; mutable std::mutex mutex_; + std::atomic isAttachThread_ = false; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/ets/ani/ani_common/include/ets_enviroment_callback.h b/frameworks/ets/ani/ani_common/include/ets_enviroment_callback.h index 72b0edef9f1..80ff2669c53 100644 --- a/frameworks/ets/ani/ani_common/include/ets_enviroment_callback.h +++ b/frameworks/ets/ani/ani_common/include/ets_enviroment_callback.h @@ -25,17 +25,20 @@ namespace AbilityRuntime { class EtsEnviromentCallback : public EnvironmentCallback, public std::enable_shared_from_this { public: - explicit EtsEnviromentCallback(ani_env *env); + explicit EtsEnviromentCallback(ani_vm *etsVm); + ~EtsEnviromentCallback() override; void OnConfigurationUpdated(const AppExecFwk::Configuration &config) override; void OnMemoryLevel(const int level) override; int32_t Register(ani_object aniCallback); bool UnRegister(int32_t callbackId); - + ani_env *AttachCurrentThread(); + void DetachCurrentThread(); private: - ani_env *env_ = nullptr; + ani_vm *etsVm_ = nullptr; std::map enviromentAniCallbacks_; int32_t serialNumber_ = 0; std::mutex Mutex_; + std::atomic isAttachThread_ = false; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp index 918e4811e90..463886f9f0f 100644 --- a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp @@ -71,8 +71,12 @@ ani_int EtsApplicationContextUtils::OnNativeOnEnvironmentSync(ani_env *env, ani_ if (etsEnviromentCallback_ != nullptr) { return etsEnviromentCallback_->Register(envCallback); } - - etsEnviromentCallback_ = std::make_shared(env); + ani_vm *aniVM = nullptr; + if (env->GetVM(&aniVM) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "get aniVM failed"); + return ANI_ERROR; + } + etsEnviromentCallback_ = std::make_shared(aniVM); int32_t callbackId = etsEnviromentCallback_->Register(envCallback); applicationContext->RegisterEnvironmentCallback(etsEnviromentCallback_); @@ -128,7 +132,12 @@ void EtsApplicationContextUtils::OnNativeOnApplicationStateChangeSync(ani_env *e applicationStateCallback_->Register(callback); return; } - applicationStateCallback_ = std::make_shared(env); + ani_vm *aniVM = nullptr; + if (env->GetVM(&aniVM) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "get aniVM failed"); + return; + } + applicationStateCallback_ = std::make_shared(aniVM); applicationStateCallback_->Register(callback); applicationContext->RegisterApplicationStateChangeCallback(applicationStateCallback_); } diff --git a/frameworks/ets/ani/ani_common/src/ets_application_state_change_callback.cpp b/frameworks/ets/ani/ani_common/src/ets_application_state_change_callback.cpp index e6e693a18eb..756c8c2f931 100644 --- a/frameworks/ets/ani/ani_common/src/ets_application_state_change_callback.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_application_state_change_callback.cpp @@ -24,35 +24,58 @@ constexpr const char* APPLICATION_STATE_CHANGE_CALLBACK = "L@ohos/app/ability/ApplicationStateChangeCallback/ApplicationStateChangeCallbackInner;"; } -EtsApplicationStateChangeCallback::EtsApplicationStateChangeCallback(ani_env *env) - : env_(env) +EtsApplicationStateChangeCallback::EtsApplicationStateChangeCallback(ani_vm *etsVm) : etsVm_(etsVm) {} + +EtsApplicationStateChangeCallback::~EtsApplicationStateChangeCallback() { -} + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); + return; + } + ani_status status = ANI_ERROR; + std::lock_guard lock(mutex_); + for (auto &callback : callbacks_) { + if (!callback) { + TAG_LOGE(AAFwkTag::APPKIT, "Invalid aniCallback"); + continue; + } + if ((status = env->GlobalReference_Delete(callback)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Delete status: %{public}d", status); + } + } + DetachCurrentThread(); +}; void EtsApplicationStateChangeCallback::CallEtsMethod(const std::string &methodName) { TAG_LOGD(AAFwkTag::APPKIT, "MethodName = %{public}s", methodName.c_str()); - if (env_ == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null env"); + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); return; } ani_class cls {}; - ani_status status = env_->FindClass(APPLICATION_STATE_CHANGE_CALLBACK, &cls); + ani_status status = ANI_ERROR; + status = env->FindClass(APPLICATION_STATE_CHANGE_CALLBACK, &cls); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "FindClass status: %{public}d", status); + DetachCurrentThread(); return; } ani_method method {}; - if ((status = env_->Class_FindMethod(cls, methodName.c_str(), nullptr, &method)) != ANI_OK) { + if ((status = env->Class_FindMethod(cls, methodName.c_str(), nullptr, &method)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Class_FindMethod status: %{public}d", status); + DetachCurrentThread(); return; } std::lock_guard lock(mutex_); for (auto &callback : callbacks_) { - if ((status = env_->Object_CallMethod_Void(reinterpret_cast(callback), method)) != ANI_OK) { + if ((status = env->Object_CallMethod_Void(reinterpret_cast(callback), method)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Object_CallMethod_Void status: %{public}d", status); } } + DetachCurrentThread(); } void EtsApplicationStateChangeCallback::NotifyApplicationForeground() @@ -67,26 +90,34 @@ void EtsApplicationStateChangeCallback::NotifyApplicationBackground() void EtsApplicationStateChangeCallback::Register(ani_object aniCallback) { - if (env_ == nullptr || aniCallback == nullptr) { + if (aniCallback == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null env or aniCallback"); return; } ani_ref aniCallbackRef = nullptr; ani_status status = ANI_ERROR; - if ((status = env_->GlobalReference_Create(aniCallback, &aniCallbackRef)) != ANI_OK) { + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); + return; + } + if ((status = env->GlobalReference_Create(aniCallback, &aniCallbackRef)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Create status : %{public}d", status); + DetachCurrentThread(); return; } std::lock_guard lock(mutex_); callbacks_.emplace(aniCallbackRef); + DetachCurrentThread(); } bool EtsApplicationStateChangeCallback::UnRegister(ani_object aniCallback) { ani_status status = ANI_ERROR; std::lock_guard lock(mutex_); - if (env_ == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null env"); + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); return false; } if (aniCallback == nullptr) { @@ -96,11 +127,12 @@ bool EtsApplicationStateChangeCallback::UnRegister(ani_object aniCallback) TAG_LOGE(AAFwkTag::APPKIT, "Invalid aniCallback"); continue; } - if ((status = env_->GlobalReference_Delete(callback)) != ANI_OK) { + if ((status = env->GlobalReference_Delete(callback)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Delete status: %{public}d", status); } } callbacks_.clear(); + DetachCurrentThread(); return true; } for (auto &callback : callbacks_) { @@ -109,15 +141,18 @@ bool EtsApplicationStateChangeCallback::UnRegister(ani_object aniCallback) continue; } ani_boolean isEqual = false; - env_->Reference_StrictEquals(aniCallback, callback, &isEqual); + env->Reference_StrictEquals(aniCallback, callback, &isEqual); if (isEqual) { - if ((status = env_->GlobalReference_Delete(callback)) != ANI_OK) { + if ((status = env->GlobalReference_Delete(callback)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Delete status: %{public}d", status); + DetachCurrentThread(); return false; } + DetachCurrentThread(); return callbacks_.erase(callback) == 1; } } + DetachCurrentThread(); return false; } @@ -126,5 +161,30 @@ bool EtsApplicationStateChangeCallback::IsEmpty() const std::lock_guard lock(mutex_); return callbacks_.empty(); } + +ani_env *EtsApplicationStateChangeCallback::AttachCurrentThread() +{ + ani_env *env = nullptr; + ani_status status = ANI_ERROR; + if ((status = etsVm_->GetEnv(ANI_VERSION_1, &env)) == ANI_OK) { + return env; + } + ani_option interopEnabled { "--interop=disable", nullptr }; + ani_options aniArgs { 1, &interopEnabled }; + if ((status = etsVm_->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &env)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "status: %{public}d", status); + return nullptr; + } + isAttachThread_ = true; + return env; +} + +void EtsApplicationStateChangeCallback::DetachCurrentThread() +{ + if (isAttachThread_) { + etsVm_->DetachCurrentThread(); + isAttachThread_ = false; + } +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/ets/ani/ani_common/src/ets_enviroment_callback.cpp b/frameworks/ets/ani/ani_common/src/ets_enviroment_callback.cpp index ca8816f1ce4..1e911fab720 100644 --- a/frameworks/ets/ani/ani_common/src/ets_enviroment_callback.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_enviroment_callback.cpp @@ -32,14 +32,28 @@ constexpr const char* APPLICATION_MEMORYLEVEL_ENUM = constexpr const char* APPLICATION_CONFIGURATION = "L@ohos/app/ability/Configuration/Configuration;:V"; } -EtsEnviromentCallback::EtsEnviromentCallback(ani_env *env) - : env_(env) {} +EtsEnviromentCallback::EtsEnviromentCallback(ani_vm *etsVm) : etsVm_(etsVm) {} -int32_t EtsEnviromentCallback::Register(ani_object aniCallback) +EtsEnviromentCallback::~EtsEnviromentCallback() { - if (env_ == nullptr) { - return -1; + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); + return; + } + ani_status status = ANI_ERROR; + std::lock_guard lock(Mutex_); + for (auto it = enviromentAniCallbacks_.begin(); it != enviromentAniCallbacks_.end();) { + if ((status = env->GlobalReference_Delete(it->second)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Delete status: %{public}d", status); + } + it++; } + DetachCurrentThread(); +}; + +int32_t EtsEnviromentCallback::Register(ani_object aniCallback) +{ int32_t callbackId = serialNumber_; if (serialNumber_ < INT32_MAX) { serialNumber_++; @@ -47,10 +61,20 @@ int32_t EtsEnviromentCallback::Register(ani_object aniCallback) serialNumber_ = 0; } ani_ref aniCallbackRef = nullptr; - env_->GlobalReference_Create(aniCallback, &aniCallbackRef); - + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); + return -1; + } + ani_status status = ANI_ERROR; + if ((status = env->GlobalReference_Create(aniCallback, &aniCallbackRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Create status: %{public}d", status); + DetachCurrentThread(); + return -1; + } std::lock_guard lock(Mutex_); enviromentAniCallbacks_.emplace(callbackId, aniCallbackRef); + DetachCurrentThread(); return callbackId; } @@ -62,33 +86,53 @@ bool EtsEnviromentCallback::UnRegister(int32_t callbackId) TAG_LOGE(AAFwkTag::APPKIT, "callbackId: %{public}d not in callbacks_", callbackId); return false; } + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); + return false; + } TAG_LOGD(AAFwkTag::APPKIT, "callbacks_.callbackId: %{public}d", it->first); + ani_status status = ANI_ERROR; + if ((status = env->GlobalReference_Delete(it->second)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "GlobalReference_Delete status: %{public}d", status); + DetachCurrentThread(); + return false; + } + DetachCurrentThread(); return enviromentAniCallbacks_.erase(callbackId) == 1; } void EtsEnviromentCallback::OnMemoryLevel(const int level) { TAG_LOGD(AAFwkTag::APPKIT, "OnMemoryLevel Call"); - if (env_ == nullptr || enviromentAniCallbacks_.empty()) { - TAG_LOGE(AAFwkTag::APPKIT, "null aniEnv"); + if (enviromentAniCallbacks_.empty()) { + TAG_LOGE(AAFwkTag::APPKIT, "null enviromentAniCallbacks_"); + return; + } + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); return; } ani_class cls {}; - ani_status status = env_->FindClass(APPLICATION_ENVIROMENT_CALLBACK, &cls); + ani_status status = env->FindClass(APPLICATION_ENVIROMENT_CALLBACK, &cls); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "FindClass status: %{public}d", status); + DetachCurrentThread(); return; } ani_method method {}; - if ((status = env_->Class_FindMethod(cls, "onMemoryLevel", APPLICATION_MEMORYLEVEL, &method)) != ANI_OK) { + if ((status = env->Class_FindMethod(cls, "onMemoryLevel", APPLICATION_MEMORYLEVEL, &method)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Class_FindMethod status: %{public}d", status); + DetachCurrentThread(); return; } ani_enum_item memoryLevel {}; - OHOS::AAFwk::AniEnumConvertUtil::EnumConvert_NativeToEts(env_, + OHOS::AAFwk::AniEnumConvertUtil::EnumConvert_NativeToEts(env, APPLICATION_MEMORYLEVEL_ENUM, (AppExecFwk::MemoryLevel)level, memoryLevel); if (memoryLevel == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "create memoryLevel failed"); + DetachCurrentThread(); return; } std::lock_guard lock(Mutex_); @@ -96,37 +140,47 @@ void EtsEnviromentCallback::OnMemoryLevel(const int level) ani_status status = ANI_ERROR; if (!callback.second) { TAG_LOGE(AAFwkTag::APPKIT, "callback object is null"); + DetachCurrentThread(); return; } ani_object envCallback = reinterpret_cast(callback.second); - if ((status = env_->Object_CallMethod_Void(envCallback, method, memoryLevel)) != ANI_OK) { + if ((status = env->Object_CallMethod_Void(envCallback, method, memoryLevel)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Object_CallMethod_Void status: %{public}d", status); } } + DetachCurrentThread(); } void EtsEnviromentCallback::OnConfigurationUpdated(const AppExecFwk::Configuration &config) { TAG_LOGD(AAFwkTag::APPKIT, "OnConfigurationUpdated Call"); - if (env_ == nullptr || enviromentAniCallbacks_.empty()) { - TAG_LOGE(AAFwkTag::APPKIT, "null aniEnv"); + if (enviromentAniCallbacks_.empty()) { + TAG_LOGE(AAFwkTag::APPKIT, "null enviromentAniCallbacks_"); + return; + } + ani_env *env = AttachCurrentThread(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "GetEnv failed"); return; } ani_class cls {}; - ani_status status = env_->FindClass(APPLICATION_ENVIROMENT_CALLBACK, &cls); + ani_status status = env->FindClass(APPLICATION_ENVIROMENT_CALLBACK, &cls); if (status != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "FindClass status: %{public}d", status); + DetachCurrentThread(); return; } ani_method method {}; - if ((status = env_->Class_FindMethod(cls, "onConfigurationUpdated", + if ((status = env->Class_FindMethod(cls, "onConfigurationUpdated", APPLICATION_CONFIGURATION, &method)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Class_FindMethod status: %{public}d", status); + DetachCurrentThread(); return; } - ani_object configObj = OHOS::AppExecFwk::WrapConfiguration(env_, config); + ani_object configObj = OHOS::AppExecFwk::WrapConfiguration(env, config); if (configObj == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "create configObj failed"); + DetachCurrentThread(); return; } std::lock_guard lock(Mutex_); @@ -134,13 +188,40 @@ void EtsEnviromentCallback::OnConfigurationUpdated(const AppExecFwk::Configurati ani_status status = ANI_ERROR; if (!callback.second) { TAG_LOGE(AAFwkTag::APPKIT, "callback object is null"); + DetachCurrentThread(); return; } ani_object envCallback = reinterpret_cast(callback.second); - if ((status = env_->Object_CallMethod_Void(envCallback, method, configObj)) != ANI_OK) { + if ((status = env->Object_CallMethod_Void(envCallback, method, configObj)) != ANI_OK) { TAG_LOGE(AAFwkTag::APPKIT, "Object_CallMethod_Void status: %{public}d", status); } } + DetachCurrentThread(); +} + +ani_env *EtsEnviromentCallback::AttachCurrentThread() +{ + ani_env *env = nullptr; + ani_status status = ANI_ERROR; + if ((status = etsVm_->GetEnv(ANI_VERSION_1, &env)) == ANI_OK) { + return env; + } + ani_option interopEnabled { "--interop=disable", nullptr }; + ani_options aniArgs { 1, &interopEnabled }; + if ((status = etsVm_->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &env)) != ANI_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "status: %{public}d", status); + return nullptr; + } + isAttachThread_ = true; + return env; +} + +void EtsEnviromentCallback::DetachCurrentThread() +{ + if (isAttachThread_) { + etsVm_->DetachCurrentThread(); + isAttachThread_ = false; + } } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp b/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp index db2bd736cdb..ce4634f7dcf 100644 --- a/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp +++ b/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp @@ -373,7 +373,7 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent TAG_LOGE(AAFwkTag::WANTAGENT, "wants GetProperty status: %{public}d, or null wantsRef", status); return PARAMETER_ERROR; } - ani_array_ref wantsArr = reinterpret_cast(wantsRef); + ani_array wantsArr = reinterpret_cast(wantsRef); ani_size length = 0; if ((status = env->Array_GetLength(wantsArr, &length)) != ANI_OK) { TAG_LOGE(AAFwkTag::WANTAGENT, "wants Array_GetLength failed status: %{public}d", status); @@ -381,8 +381,8 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent } for (size_t i = 0; i < length; i++) { ani_ref wantRef = nullptr; - if ((status = env->Array_Get_Ref(wantsArr, i, &wantRef)) != ANI_OK || wantRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get_Ref failed status: %{public}d, or null wantRef", status); + if ((status = env->Array_Get(wantsArr, i, &wantRef)) != ANI_OK || wantRef == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get failed status: %{public}d, or null wantRef", status); return PARAMETER_ERROR; } std::shared_ptr want = std::make_shared(); @@ -395,8 +395,8 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent ani_boolean isUndefined = true; ani_ref actionTypeRef = nullptr; - if (!GetPropertyRef(env, info, "actionType", actionTypeRef, isUndefined) || actionTypeRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "GetPropertyRef failed, or null actionTypeRef"); + if (!GetPropertyRef(env, info, "actionType", actionTypeRef, isUndefined)) { + TAG_LOGE(AAFwkTag::WANTAGENT, "actionType GetPropertyRef failed"); return PARAMETER_ERROR; } if (!isUndefined) { @@ -406,18 +406,18 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent ani_double dRequestCode = 0.0; if ((status = env->Object_GetPropertyByName_Double(info, "requestCode", &dRequestCode)) != ANI_OK) { - TAG_LOGE(AAFwkTag::WANTAGENT, "Object_GetPropertyByName_Double failed status: %{public}d", status); + TAG_LOGE(AAFwkTag::WANTAGENT, "requestCode GetProperty failed status: %{public}d", status); return PARAMETER_ERROR; } params.requestCode = dRequestCode; ani_ref actionFlagsRef = nullptr; - if (!GetPropertyRef(env, info, "actionFlags", actionFlagsRef, isUndefined) || actionFlagsRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "GetPropertyRef failed, or null actionFlagsRef"); + if (!GetPropertyRef(env, info, "actionFlags", actionFlagsRef, isUndefined)) { + TAG_LOGE(AAFwkTag::WANTAGENT, "actionFlags GetPropertyRef failed"); return PARAMETER_ERROR; } - ani_array_ref actionFlagsArr = reinterpret_cast(actionFlagsRef); if (!isUndefined) { + ani_array actionFlagsArr = reinterpret_cast(actionFlagsRef); ani_size actionFlagsLen = 0; if ((status = env->Array_GetLength(actionFlagsArr, &actionFlagsLen)) != ANI_OK) { TAG_LOGE(AAFwkTag::WANTAGENT, "Array_GetLength failed status: %{public}d", status); @@ -425,9 +425,9 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent } for (size_t i = 0; i < actionFlagsLen; i++) { ani_ref actionFlagRef = nullptr; - if ((status = env->Array_Get_Ref(actionFlagsArr, i, &actionFlagRef)) != ANI_OK || + if ((status = env->Array_Get(actionFlagsArr, i, &actionFlagRef)) != ANI_OK || actionFlagRef == nullptr) { - TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get_Ref failed status: %{public}d, or null actionFlagRef", status); + TAG_LOGE(AAFwkTag::WANTAGENT, "Array_Get failed status: %{public}d, or null actionFlagRef", status); return PARAMETER_ERROR; } int32_t actionFlag = 0; @@ -439,12 +439,12 @@ int32_t EtsWantAgent::GetWantAgentParam(ani_env *env, ani_object info, WantAgent ani_ref extraInfoRef = nullptr; if (!GetPropertyRef(env, info, "extraInfos", extraInfoRef, isUndefined)) { - TAG_LOGE(AAFwkTag::WANTAGENT, "GetPropertyRef failed"); + TAG_LOGE(AAFwkTag::WANTAGENT, "extraInfos GetPropertyRef failed"); return PARAMETER_ERROR; } if (isUndefined) { if (!GetPropertyRef(env, info, "extraInfo", extraInfoRef, isUndefined)) { - TAG_LOGE(AAFwkTag::WANTAGENT, "GetPropertyRef failed"); + TAG_LOGE(AAFwkTag::WANTAGENT, "extraInfo GetPropertyRef failed"); return PARAMETER_ERROR; } } diff --git a/frameworks/ets/ets/wantAgent/wantAgentInfo.ets b/frameworks/ets/ets/wantAgent/wantAgentInfo.ets index 4487de50bf1..ae0859b67e6 100644 --- a/frameworks/ets/ets/wantAgent/wantAgentInfo.ets +++ b/frameworks/ets/ets/wantAgent/wantAgentInfo.ets @@ -19,10 +19,8 @@ import type abilityWantAgent from '@ohos.app.ability.wantAgent'; export interface WantAgentInfo { wants: Array; - operationType?: wantAgent.OperationType; actionType?: abilityWantAgent.OperationType; requestCode: number; - wantAgentFlags?: Array; actionFlags?: Array; extraInfo?: Record; extraInfos?: Record; @@ -30,10 +28,8 @@ export interface WantAgentInfo { class WantAgentInfoImpl implements WantAgentInfo { public wants: Array; - public operationType?: wantAgent.OperationType; public actionType?: abilityWantAgent.OperationType; public requestCode: number; - public wantAgentFlags?: Array; public actionFlags?: Array; public extraInfo?: Record; public extraInfos?: Record; -- Gitee From c4d8912e27e50092ad59df90fddf907cc2b85674 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:43:15 +0800 Subject: [PATCH 06/16] merge 15698 Signed-off-by: zhang_hao_zheng Change-Id: I5135ee159e5df12c73c097bc434fe55d236635d9 --- .../ets/ani/ani_common/src/ets_data_struct_converter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/ets/ani/ani_common/src/ets_data_struct_converter.cpp b/frameworks/ets/ani/ani_common/src/ets_data_struct_converter.cpp index a5621eb853c..9f273c9c825 100644 --- a/frameworks/ets/ani/ani_common/src/ets_data_struct_converter.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_data_struct_converter.cpp @@ -148,6 +148,11 @@ bool WrapLaunchParam(ani_env *env, const AAFwk::LaunchParam &launchParam, ani_ob TAG_LOGE(AAFwkTag::ETSRUNTIME, "Failed to set lastExitMessage"); return false; } + if ((status = env->Object_SetPropertyByName_Ref( + object, "launchReasonMessage", GetAniString(env, launchParam.launchReasonMessage))) != ANI_OK) { + TAG_LOGE(AAFwkTag::ETSRUNTIME, "Failed to set launchReasonMessage"); + return false; + } return WrapLaunchParamInner(env, launchParam, object); } } // namespace AbilityRuntime -- Gitee From b548d45d5ea81b467997f809fbed0ae1b3da2176 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:44:04 +0800 Subject: [PATCH 07/16] merge 15787 Signed-off-by: zhang_hao_zheng Change-Id: I1ef1c144dd2510fc1fb6db148692a0cf10eddc8f --- .../ets/ani/ani_common/src/ets_application_context_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp index 463886f9f0f..abff791b05b 100644 --- a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp @@ -294,7 +294,7 @@ void EtsApplicationContextUtils::OnSetFont(ani_env *env, ani_object aniObj, ani_ return; } std::string stdFont = ""; - if (!AppExecFwk::GetStdString(env, font, stdFont)) { + if (!AppExecFwk::GetStdString(env, font, stdFont) || stdFont.empty()) { TAG_LOGE(AAFwkTag::APPKIT, "Parse font failed"); EtsErrorUtil::ThrowInvalidParamError(env, "Parse param font failed, font must be string."); return; @@ -336,7 +336,7 @@ void EtsApplicationContextUtils::OnSetLanguage(ani_env *env, ani_object aniObj, return; } std::string stdLanguage = ""; - if (!AppExecFwk::GetStdString(env, language, stdLanguage)) { + if (!AppExecFwk::GetStdString(env, language, stdLanguage) || stdLanguage.empty()) { TAG_LOGE(AAFwkTag::APPKIT, "Parse language failed"); EtsErrorUtil::ThrowInvalidParamError(env, "Parse param language failed, language must be string."); return; -- Gitee From 697d9fa5797b63fbc02d035ad9b9d26b10ab14b7 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:45:01 +0800 Subject: [PATCH 08/16] merge 15789 Signed-off-by: zhang_hao_zheng Change-Id: I3d03f9ec28ac58845d2c3070f97e75bcbf6b2a3b --- .../ani/ani_common/src/ets_application_context_utils.cpp | 1 + frameworks/ets/ani/ani_common/src/ets_context_utils.cpp | 6 +++--- frameworks/ets/ani/application/src/ets_application.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp index abff791b05b..be8d6629027 100644 --- a/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp @@ -970,6 +970,7 @@ ani_object EtsApplicationContextUtils::CreateEtsApplicationContext(ani_env* aniE } auto etsReference = std::make_shared(); etsReference->aniObj = applicationContextObject; + etsReference->aniRef = applicationContextObjectRef; ApplicationContextManager::GetApplicationContextManager().SetEtsGlobalObject(etsReference); BindApplicationContextFunc(aniEnv); ani_class applicationContextClass = nullptr; diff --git a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp index 481a88af279..302cf57af0d 100644 --- a/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp +++ b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp @@ -662,9 +662,9 @@ ani_object GetApplicationContextSync(ani_env *env, ani_object aniObj) } if (!applicationContext->GetApplicationInfoUpdateFlag()) { auto appContextObj = ApplicationContextManager::GetApplicationContextManager().GetEtsGlobalObject(); - if (appContextObj != nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "appContextObj is not nullptr"); - return appContextObj->aniObj; + if (appContextObj != nullptr && appContextObj->aniRef != nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "appContextObj is not nullptr"); + return reinterpret_cast(appContextObj->aniRef); } } return GetApplicationContext(env, applicationContext); diff --git a/frameworks/ets/ani/application/src/ets_application.cpp b/frameworks/ets/ani/application/src/ets_application.cpp index 7c09dc6fa34..e395fac644c 100644 --- a/frameworks/ets/ani/application/src/ets_application.cpp +++ b/frameworks/ets/ani/application/src/ets_application.cpp @@ -253,14 +253,14 @@ ani_object EtsApplication::GetApplicationContext(ani_env *env) } auto etsReference = AbilityRuntime::ApplicationContextManager::GetApplicationContextManager().GetEtsGlobalObject(); - if (etsReference == nullptr || etsReference->aniObj == nullptr) { + if (etsReference == nullptr || etsReference->aniRef == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null applicationContextObject"); AbilityRuntime::EtsErrorUtil::ThrowError(env, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER); ani_ref result = nullptr; env->GetNull(&result); return static_cast(result); } - return etsReference->aniObj; + return reinterpret_cast(etsReference->aniRef); } void ApplicationInit(ani_env *env) -- Gitee From bb97f556d166dc2241de64ed3d132b02d9996d27 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:46:58 +0800 Subject: [PATCH 09/16] merge 15803 Signed-off-by: zhang_hao_zheng Change-Id: Icd7c8b8fe9d82fb73e6f371255787f5a375fea45 --- .../ets/ani/ability_delegator/src/ets_ability_monitor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frameworks/ets/ani/ability_delegator/src/ets_ability_monitor.cpp b/frameworks/ets/ani/ability_delegator/src/ets_ability_monitor.cpp index 84e2ce4d31c..67a3c40b22e 100644 --- a/frameworks/ets/ani/ability_delegator/src/ets_ability_monitor.cpp +++ b/frameworks/ets/ani/ability_delegator/src/ets_ability_monitor.cpp @@ -154,7 +154,13 @@ void EtsAbilityMonitor::CallLifecycleCBFunction(const std::string &functionName, TAG_LOGE(AAFwkTag::DELEGATOR, "Object_GetField_Ref failed status: %{public}d", status); return; } - + ani_boolean isValue = false; + ani_boolean isUndefined = false; + env->Reference_IsNullishValue(funRef, &isValue); + env->Reference_IsUndefined(funRef, &isUndefined); + if (isUndefined || isValue) { + return; + } ani_fn_object onFn = reinterpret_cast(funRef); ani_ref resutlt; std::vector argv = { abilityObj->aniRef }; -- Gitee From 20c862df1f63469689cca0d27c04d0a0c3fdd1f2 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:47:54 +0800 Subject: [PATCH 10/16] merge 15820 Signed-off-by: zhang_hao_zheng Change-Id: I5e7a781295aec52b7edfdc93095852571026b620 --- frameworks/ets/ani/application/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/ets/ani/application/BUILD.gn b/frameworks/ets/ani/application/BUILD.gn index b9be6b35a2f..2ec039ad551 100644 --- a/frameworks/ets/ani/application/BUILD.gn +++ b/frameworks/ets/ani/application/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("application_ani") { external_deps = [ "ability_base:configuration", "bundle_framework:appexecfwk_core", + "c_utils:utils", "hilog:libhilog", "json:nlohmann_json_static", "ipc:ipc_core", -- Gitee From 551dc1851cb9a81a359e02d7f8f9c7826d3274f9 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:48:52 +0800 Subject: [PATCH 11/16] merge 15732 Signed-off-by: zhang_hao_zheng Change-Id: I1d850c6f399aa4035c0cffb2952d08bc4a216b9e --- frameworks/ets/ani/ability_delegator/BUILD.gn | 1 + frameworks/ets/ani/ability_manager/BUILD.gn | 1 + frameworks/ets/ani/application/BUILD.gn | 1 + frameworks/ets/ani/insight_intent/insight_intent_driver/BUILD.gn | 1 + frameworks/ets/ani/uri_permission_manager/BUILD.gn | 1 + frameworks/ets/ani/wantagent/BUILD.gn | 1 + 6 files changed, 6 insertions(+) diff --git a/frameworks/ets/ani/ability_delegator/BUILD.gn b/frameworks/ets/ani/ability_delegator/BUILD.gn index d711786523b..c8385f189ed 100644 --- a/frameworks/ets/ani/ability_delegator/BUILD.gn +++ b/frameworks/ets/ani/ability_delegator/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("ability_delegator_registry_ani_kit") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/frameworks/ets/ani/ability_manager/BUILD.gn b/frameworks/ets/ani/ability_manager/BUILD.gn index 1b341d09719..ad7821254d0 100644 --- a/frameworks/ets/ani/ability_manager/BUILD.gn +++ b/frameworks/ets/ani/ability_manager/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("ability_manager_ani_kit") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/frameworks/ets/ani/application/BUILD.gn b/frameworks/ets/ani/application/BUILD.gn index 2ec039ad551..977fd2b0d60 100644 --- a/frameworks/ets/ani/application/BUILD.gn +++ b/frameworks/ets/ani/application/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("application_ani") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/frameworks/ets/ani/insight_intent/insight_intent_driver/BUILD.gn b/frameworks/ets/ani/insight_intent/insight_intent_driver/BUILD.gn index 10a6e89f0d2..4727105552b 100644 --- a/frameworks/ets/ani/insight_intent/insight_intent_driver/BUILD.gn +++ b/frameworks/ets/ani/insight_intent/insight_intent_driver/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("insight_intent_driver_ani_kit") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/frameworks/ets/ani/uri_permission_manager/BUILD.gn b/frameworks/ets/ani/uri_permission_manager/BUILD.gn index ea9f3d4ec41..d4f9f077755 100644 --- a/frameworks/ets/ani/uri_permission_manager/BUILD.gn +++ b/frameworks/ets/ani/uri_permission_manager/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("uri_permission_manager_ani_kit") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/frameworks/ets/ani/wantagent/BUILD.gn b/frameworks/ets/ani/wantagent/BUILD.gn index 1bf1b8ec940..2d57e00c5c6 100644 --- a/frameworks/ets/ani/wantagent/BUILD.gn +++ b/frameworks/ets/ani/wantagent/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") ohos_shared_library("aniwantagent") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { cfi = true -- Gitee From eff3c63d931e4fd4060f4f4d9cd7e6fcfb8788ab Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:49:47 +0800 Subject: [PATCH 12/16] merge 15851 Signed-off-by: zhang_hao_zheng Change-Id: Id2f729fbc4bbe76bbea6d422d5fc688a6bf0e64d --- frameworks/ets/ets/@ohos.app.ability.Want.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ets/ets/@ohos.app.ability.Want.ets b/frameworks/ets/ets/@ohos.app.ability.Want.ets index 3d0cbd3d008..6d7c75b3136 100644 --- a/frameworks/ets/ets/@ohos.app.ability.Want.ets +++ b/frameworks/ets/ets/@ohos.app.ability.Want.ets @@ -154,7 +154,7 @@ class RecordWriter { export class RecordSerializeTool { public static stringifyNoThrow(obj: Record): String { try { - return RecordSerializeTool.stringify(obj as Object as Record); + return JSON.stringify(obj as Object as Record); } catch (err) { hilog.error(DOMAIN_ID, TAG, `RecordSerializeTool.stringify error: ${err}`); return ''; -- Gitee From 97dbfd0ddcafe5aa29b9c6932bbee0306b936e67 Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Wed, 6 Aug 2025 15:50:43 +0800 Subject: [PATCH 13/16] merge 15846 Signed-off-by: zhang_hao_zheng Change-Id: I552dda8f1e5febcdfd66a7fc385447cb5d53149d --- .../application/ServiceExtensionContext.ets | 35 ++++---- .../ets/ets/application/UIAbilityContext.ets | 88 +++++++------------ .../ets/application/UIExtensionContext.ets | 41 ++++----- 3 files changed, 66 insertions(+), 98 deletions(-) diff --git a/frameworks/ets/ets/application/ServiceExtensionContext.ets b/frameworks/ets/ets/application/ServiceExtensionContext.ets index 569ada6a428..2bb11c2f1f5 100644 --- a/frameworks/ets/ets/application/ServiceExtensionContext.ets +++ b/frameworks/ets/ets/application/ServiceExtensionContext.ets @@ -101,26 +101,25 @@ export default class ServiceExtensionContext extends ExtensionContext { }); } - startAbility(want: Want, options: StartOptions, callback: AsyncCallback): void { - let myCall = new AsyncCallbackWrapper(callback); - taskpool.execute((): void => { - this.nativeStartAbility(want, options, myCall); - }); - } - - startAbility(want: Want, options: StartOptions): Promise { + startAbility(want: Want, options?: StartOptions): Promise { return new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { - let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { - if (err == null || err.code == 0) { - resolve(undefined); - } else { - reject(err); - } - }); - taskpool.execute((): void => { - this.nativeStartAbility(want, options, myCall); - }); + let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { + if (err == null || err.code == 0) { + resolve(undefined); + } else { + reject(err); + } + }); + taskpool.execute((): void => { + if (options == null) { + this.nativeStartAbility(want, myCall); + } else { + this.nativeStartAbility(want, options as StartOptions, myCall); + } + }).catch((err: Error): void => { + reject(err as BusinessError); }); + }); } startServiceExtensionAbility(want: Want, callback: AsyncCallback): void { diff --git a/frameworks/ets/ets/application/UIAbilityContext.ets b/frameworks/ets/ets/application/UIAbilityContext.ets index 4be5cc5c242..0d629d1c62c 100644 --- a/frameworks/ets/ets/application/UIAbilityContext.ets +++ b/frameworks/ets/ets/application/UIAbilityContext.ets @@ -148,38 +148,25 @@ export default class UIAbilityContext extends Context { }); } - startAbility(want: Want): Promise { - let p: Promise = - new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { - let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { - if (err == null || err.code == 0) { - resolve(undefined); - } else { - reject(err); - } - }); - taskpool.execute((): void => { - this.nativeStartAbilitySync(want, myCall); - }); + startAbility(want: Want, options?: StartOptions): Promise { + return new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { + if (err == null || err.code == 0) { + resolve(undefined); + } else { + reject(err); + } }); - return p; - } - - startAbility(want: Want, options: StartOptions): Promise { - let p = - new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { - let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { - if (err == null || err.code == 0) { - resolve(undefined); - } else { - reject(err); - } - }); - taskpool.execute((): void => { - this.nativeStartAbilitySync(want, options, myCall); - }); + taskpool.execute((): void => { + if (options == null) { + this.nativeStartAbilitySync(want, myCall); + } else { + this.nativeStartAbilitySync(want, options as StartOptions, myCall); + } + }).catch((err: Error): void => { + reject(err as BusinessError); }); - return p; + }); } startAbilityForResult(want: Want, callback: AsyncCallback): void { @@ -196,38 +183,27 @@ export default class UIAbilityContext extends Context { }); } - startAbilityForResult(want: Want): Promise { - let p = new Promise((resolve: (data: AbilityResult) => void, + startAbilityForResult(want: Want, startOptions?: StartOptions): Promise { + return new Promise((resolve: (data: AbilityResult) => void, reject: (err: BusinessError) => void): void => { - let myCall = new AsyncCallbackWrapper((err: BusinessError | null, data: AbilityResult | undefined) => { - if (err == null || err.code == 0) { - resolve(data as AbilityResult); - } else { - reject(err); - } - }); + let myCall = + new AsyncCallbackWrapper((err: BusinessError | null, data: AbilityResult | undefined) => { + if (err == null || err.code == 0) { + resolve(data as AbilityResult); + } else { + reject(err); + } + }); taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, myCall); - }); - }); - return p; - } - - startAbilityForResult(want: Want, startOptions: StartOptions): Promise { - let p = new Promise((resolve: (data: AbilityResult) => void, - reject: (err: BusinessError) => void): void => { - let myCall = new AsyncCallbackWrapper((err: BusinessError | null, data: AbilityResult | undefined) => { - if (err == null || err.code == 0) { - resolve(data as AbilityResult); + if (startOptions == null) { + this.nativeStartAbilityForResult(want, myCall); } else { - reject(err); + this.nativeStartAbilityForResult(want, startOptions as StartOptions, myCall); } - }); - taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, startOptions, myCall); + }).catch((err: Error): void => { + reject(err as BusinessError); }); }); - return p; } startAbilityByCall(want: Want): Promise { diff --git a/frameworks/ets/ets/application/UIExtensionContext.ets b/frameworks/ets/ets/application/UIExtensionContext.ets index b7fb7e061ed..fc684e9764f 100644 --- a/frameworks/ets/ets/application/UIExtensionContext.ets +++ b/frameworks/ets/ets/application/UIExtensionContext.ets @@ -125,7 +125,7 @@ export default class UIExtensionContext extends ExtensionContext { }); } - startAbility(want: Want, options: StartOptions): Promise { + startAbility(want: Want, options?: StartOptions): Promise { return new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { if (err == null || err.code == 0) { @@ -135,7 +135,13 @@ export default class UIExtensionContext extends ExtensionContext { } }); taskpool.execute((): void => { - this.nativeStartAbility(want, options, myCall); + if (options == null) { + this.nativeStartAbility(want, myCall); + } else { + this.nativeStartAbility(want, options as StartOptions, myCall); + } + }).catch((err: Error): void => { + reject(err as BusinessError); }); }); } @@ -180,26 +186,8 @@ export default class UIExtensionContext extends ExtensionContext { }); } - startAbilityForResult(want: Want): Promise { - let p = new Promise((resolve: (data: AbilityResult) => void, - reject: (err: BusinessError) => void): void => { - let myCall = - new AsyncCallbackWrapper((err: BusinessError | null, data: AbilityResult | undefined) => { - if (err == null || err.code == 0) { - resolve(data as AbilityResult); - } else { - reject(err); - } - }); - taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, myCall); - }); - }); - return p; - } - - startAbilityForResult(want: Want, startOptions: StartOptions): Promise { - let p = new Promise((resolve: (data: AbilityResult) => void, + startAbilityForResult(want: Want, startOptions?: StartOptions): Promise { + return new Promise((resolve: (data: AbilityResult) => void, reject: (err: BusinessError) => void): void => { let myCall = new AsyncCallbackWrapper((err: BusinessError | null, data: AbilityResult | undefined) => { @@ -210,10 +198,15 @@ export default class UIExtensionContext extends ExtensionContext { } }); taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, startOptions, myCall); + if (startOptions == null) { + this.nativeStartAbilityForResult(want, myCall); + } else { + this.nativeStartAbilityForResult(want, startOptions as StartOptions, myCall); + } + }).catch((err: Error): void => { + reject(err as BusinessError); }); }); - return p; } reportDrawnCompleted(callback: AsyncCallback): void { -- Gitee From 9a79266a44e963035c8c4a7deba840419e803e1c Mon Sep 17 00:00:00 2001 From: zhang_hao_zheng Date: Thu, 7 Aug 2025 16:31:41 +0800 Subject: [PATCH 14/16] merge 15802 Signed-off-by: zhang_hao_zheng Change-Id: Ic314e8185a59b569ce779698dfffea598f0b5c94 --- .../ets/ani/ani_common/src/ani_common_remote.cpp | 2 +- .../src/ets_service_extension.cpp | 15 ++++++++++++--- .../src/ets_service_extension_context.cpp | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frameworks/ets/ani/ani_common/src/ani_common_remote.cpp b/frameworks/ets/ani/ani_common/src/ani_common_remote.cpp index f74600380b2..e78b9a839a1 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_remote.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_remote.cpp @@ -28,7 +28,7 @@ ani_object AniRemote::CreateAniRemoteObject(ani_env *env, const sptrClass_FindMethod(cls, "", "l:", &method)) != ANI_OK) { + if ((status = env->Class_FindMethod(cls, "", ":V", &method)) != ANI_OK) { TAG_LOGE(AAFwkTag::ABILITY, "RemoteProxy ctor: %{public}d", status); return nullptr; } diff --git a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp index 0e73682a183..c5e26b60281 100644 --- a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp +++ b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp @@ -50,7 +50,7 @@ constexpr const char *ON_CREATE_SIGNATURE = "L@ohos/app/ability/Want/Want;:V"; constexpr const char *VOID_SIGNATURE = ":V"; constexpr const char *CHECK_PROMISE_SIGNATURE = "Lstd/core/Object;:Z"; constexpr const char *CALL_PROMISE_SIGNATURE = "Lstd/core/Promise;:Z"; -constexpr const char *ON_DISCONNECT_SIGNATURE = "L@ohos/app/ability/Want/Want;:V"; +constexpr const char *ON_DISCONNECT_SIGNATURE = "L@ohos/app/ability/Want/Want;:Z"; constexpr const char *ON_REQUEST_SIGNATURE = "L@ohos/app/ability/Want/Want;I:V"; constexpr const char *ON_CONFIGURATION_UPDATE_SIGNATURE = "L@ohos/app/ability/Configuration/Configuration;:V"; constexpr const char *ON_DUMP_SIGNATURE = "Lescompat/Array;:Lescompat/Array;"; @@ -320,7 +320,7 @@ void EtsServiceExtension::OnDisconnect( HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnDisconnect"); auto env = etsRuntime_.GetAniEnv(); - if (env) { + if (env == nullptr) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); return; } @@ -350,8 +350,17 @@ void EtsServiceExtension::OnDisconnect( TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); return; } + ani_method method {}; + if ((status = env->Class_FindMethod(etsObj_->aniCls, "callOnDisconnect", ON_DISCONNECT_SIGNATURE, &method)) + != ANI_OK || method == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + return; + } ani_boolean callResult = ANI_FALSE; - CallObjectMethod(true, "callOnDisconnect", ON_DISCONNECT_SIGNATURE, &callResult, wantRef); + if ((status = env->Object_CallMethod_Boolean(etsObj_->aniObj, method, &callResult, wantRef)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + return; + } isAsyncCallback = callResult; } diff --git a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp index 05fe8a0f637..bbda8657de3 100644 --- a/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp +++ b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension_context.cpp @@ -80,7 +80,8 @@ bool BindNativeMethods(ani_env *env, ani_class &cls) std::array CleanerMethods = { ani_native_function { "clean", nullptr, reinterpret_cast(EtsServiceExtensionContext::Finalizer) }, }; - if ((status = env->Class_BindNativeMethods(cleanerCls, CleanerMethods.data(), CleanerMethods.size())) != ANI_OK) { + if ((status = env->Class_BindNativeMethods(cleanerCls, CleanerMethods.data(), CleanerMethods.size())) != ANI_OK + && status != ANI_ALREADY_BINDED) { TAG_LOGE(AAFwkTag::UI_EXT, "bind method status : %{public}d", status); return false; } -- Gitee From 0062faba6e2ae508b496d08a4689967f0c7cd445 Mon Sep 17 00:00:00 2001 From: wangzilin Date: Sat, 9 Aug 2025 14:26:06 +0800 Subject: [PATCH 15/16] transfer window class Signed-off-by: wangzilin --- frameworks/native/ability/native/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index cbfe81f15f9..b4759c3826c 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -936,6 +936,7 @@ ohos_shared_library("ui_ability_ani") { "runtime_core:ani_helpers", "samgr:samgr_proxy", "window_manager:windowstageani_kit", + "window_manager:window_native_kit", ] public_external_deps = [ "bundle_framework:appexecfwk_core", -- Gitee From ffd34de527cc4d0377c7ad1c28aa68c3175c26d2 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Tue, 12 Aug 2025 15:58:40 +0800 Subject: [PATCH 16/16] autoFillType_0812 Signed-off-by: zhangzezhong --- frameworks/ets/ets/BUILD.gn | 16 ------ .../ets/ets/application/AutoFillType.ets | 51 ------------------- 2 files changed, 67 deletions(-) delete mode 100644 frameworks/ets/ets/application/AutoFillType.ets diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 6d456a2a881..f2f3bae1174 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -905,21 +905,6 @@ ohos_prebuilt_etc("ability_runtime_connect_options_abc_etc") { deps = [ ":ability_runtime_connect_options_abc" ] } -generate_static_abc("ability_runtime_auto_fill_type_abc") { - base_url = "./" - files = [ "./application/AutoFillType.ets" ] - - is_boot_abc = "True" - device_dst_file = "/system/framework/ability_runtime_auto_fill_type_abc.abc" -} - -ohos_prebuilt_etc("ability_runtime_auto_fill_type_abc_etc") { - source = "$target_out_dir/ability_runtime_auto_fill_type_abc.abc" - module_install_dir = "framework" - subsystem_name = "ability" - part_name = "ability_runtime" - deps = [ ":ability_runtime_auto_fill_type_abc" ] -} generate_static_abc("ability_runtime_error_code_abc") { base_url = "./" @@ -1237,7 +1222,6 @@ group("ets_packages") { ":ability_runtime_app_manager_abc_etc", ":ability_runtime_app_state_data_abc_etc", ":ability_runtime_application_context_abc_etc", - ":ability_runtime_auto_fill_type_abc_etc", ":ability_runtime_application_state_change_callback_abc_etc", ":ability_runtime_base_context_abc_etc", ":ability_runtime_caller_callee_abc_etc", diff --git a/frameworks/ets/ets/application/AutoFillType.ets b/frameworks/ets/ets/application/AutoFillType.ets deleted file mode 100644 index 122dee5a175..00000000000 --- a/frameworks/ets/ets/application/AutoFillType.ets +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 enum AutoFillType { - UNSPECIFIED = 0, - PASSWORD = 1, - USER_NAME = 2, - NEW_PASSWORD = 3, - FULL_STREET_ADDRESS = 4, - HOUSE_NUMBER = 5, - DISTRICT_ADDRESS = 6, - CITY_ADDRESS = 7, - PROVINCE_ADDRESS = 8, - COUNTRY_ADDRESS = 9, - PERSON_FULL_NAME = 10, - PERSON_LAST_NAME = 11, - PERSON_FIRST_NAME = 12, - PHONE_NUMBER = 13, - PHONE_COUNTRY_CODE = 14, - FULL_PHONE_NUMBER = 15, - EMAIL_ADDRESS = 16, - BANK_CARD_NUMBER = 17, - ID_CARD_NUMBER = 18, - NICKNAME = 24, - DETAIL_INFO_WITHOUT_STREET = 25, - FORMAT_ADDRESS = 26, - PASSPORT_NUMBER = 27, - VALIDITY = 28, - ISSUE_AT = 29, - ORGANIZATION = 30, - TAX_ID = 31, - ADDRESS_CITY_AND_STATE = 32, - FLIGHT_NUMBER = 33, - LICENSE_NUMBER = 34, - LICENSE_FILE_NUMBER = 35, - LICENSE_PLATE = 36, - ENGINE_NUMBER = 37, - LICENSE_CHASSIS_NUMBER = 38 -} \ No newline at end of file -- Gitee