diff --git a/ets_environment/frameworks/ets_environment/BUILD.gn b/ets_environment/frameworks/ets_environment/BUILD.gn index 1c67d800122633704574c09186d75869cc286013..8bc85903f65b5c3cb0adfbd0dce646ee989064d0 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 f08d98593914e2025bbfd00e08cc48c139225d98..4b4f96d79acef594fec7e80e2a0143ac8e5e073b 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 c7a79c5f5708849150ee2c2fe720ed5d2877f1a1..2e9a19aea07ed8c825d04da7808054b8b9344233 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 fa6fcc369d22bb4102fac29fb8b1634ba3edb03c..935a46ef708412bcd415f773598ca741dc5bb7f9 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/ets/ani/ability_delegator/BUILD.gn b/frameworks/ets/ani/ability_delegator/BUILD.gn index d711786523b0ffc34bf674ca2a9e90366ddb886f..c8385f189ed6bb44899fc4d1345940bc2ed7f728 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_delegator/src/ets_ability_monitor.cpp b/frameworks/ets/ani/ability_delegator/src/ets_ability_monitor.cpp index 84e2ce4d31c295d6ab420775b34dbe535413e01b..67a3c40b22e369402bc42a70eba34dc97c01cd0e 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 }; diff --git a/frameworks/ets/ani/ability_manager/BUILD.gn b/frameworks/ets/ani/ability_manager/BUILD.gn index 1b341d097196fc69022d686bd6f59ebefa5f9ab8..ad7821254d0213163bf1b631a6c3d52491a69edb 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/ability_manager/src/ets_ability_manager_utils.cpp b/frameworks/ets/ani/ability_manager/src/ets_ability_manager_utils.cpp index 035e645ea1d7bdc514d6bcf467b6da69d80a416a..8d585f896d72cf83b272d2ee66ae43eb995185fd 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/include/ets_application_state_change_callback.h b/frameworks/ets/ani/ani_common/include/ets_application_state_change_callback.h index 989e30bf7489dffda16e3411afb99e45bd430fc8..07270a2e3734cf60c7679d899ba0c8c278fc4f6b 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 72b0edef9f16d731587a1f3cc13fe82bd0fb168c..80ff2669c53715439b1646ef194144089ad6beff 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/ani_common_remote.cpp b/frameworks/ets/ani/ani_common/src/ani_common_remote.cpp index f74600380b2d68ca5ee3d2364a5600f9ce27a8ff..e78b9a839a19887a87d085f7858149459d2b49c4 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/ani_common/src/ani_common_util.cpp b/frameworks/ets/ani/ani_common/src/ani_common_util.cpp index 34eda52d4aedefa5228ce3a99fdf4723f3fa06b6..1a76532c4dbb21f98aac955d545dbd73d57ac239 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/ani_common/src/ets_application_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_application_context_utils.cpp index 918e4811e9036aa1f26aa5aea3667b2f8f19e1ee..be8d6629027da4c14cb4db796c3cedd4175bf38e 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_); } @@ -285,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; @@ -327,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; @@ -961,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_application_state_change_callback.cpp b/frameworks/ets/ani/ani_common/src/ets_application_state_change_callback.cpp index e6e693a18eb53459abdd84c6b684b2097a0a2992..756c8c2f931a92347dda14564e958a18348816e3 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_context_utils.cpp b/frameworks/ets/ani/ani_common/src/ets_context_utils.cpp index 481a88af279150645d094d7d388f6ad7865da104..f8f48fafc7d17a192a0e71bcbef21d09aafa5cef 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); } } @@ -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/ani_common/src/ets_data_struct_converter.cpp b/frameworks/ets/ani/ani_common/src/ets_data_struct_converter.cpp index a5621eb853cf060f967608b27572b2a2c22a74e0..9f273c9c8252e60669641f0b5e648787a18e3250 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 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 ca8816f1ce493b28fbf10c6bda47ecddb678e3b8..1e911fab720b9c20e6b249a432941cf7868406e0 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/app_manager/src/ets_app_manager.cpp b/frameworks/ets/ani/app_manager/src/ets_app_manager.cpp index f4f9c5ea70e38ce871c52e76e1641556ed3b41ec..3b5cfdb37f601044e11e1c99da9a7fd15315c9a5 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/application/BUILD.gn b/frameworks/ets/ani/application/BUILD.gn index b9be6b35a2faf9c07f2a6a0c36e4706bbf3d79e9..977fd2b0d60a4d24405d6bcfc3071363c76baf8d 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 @@ -49,6 +50,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", diff --git a/frameworks/ets/ani/application/src/ets_application.cpp b/frameworks/ets/ani/application/src/ets_application.cpp index 7c09dc6fa34f279b71f2005fd2c5da44510aa09b..e395fac644c559d1ce5298015c53a513f8c0e94d 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) 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 10a6e89f0d253dc303f7c8f146d92d9b0c252d18..4727105552bc1752438ceafa5148b220158a9a80 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/service_extension_ability/src/ets_service_extension.cpp b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp index 0e73682a183c8faf144fcd11e577f30344ec0174..c5e26b60281f1aa4d36b0ae67311f08766869379 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 05fe8a0f6371022e20f868c40fc7e386ee189c83..bbda8657de3734a3b3c6d4039cc6f4a4fdd7c7c0 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; } 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 c1252a34b9366ec281c9df3161e6c3fcc6e9b96e..4df327ef93b52bb204e90a39bdce6f92f63a0993 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 e49bc810f7f787c7df68338e06cbad3df18fa9fe..58157cb3f789f83159fa6fa3559705fcea86eef5 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 3b5051a24834693d8d5fc0f6972d521e70fcce49..59228da3ffe737f5fa53a2b0bd91b69d591589c0 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/ani/uri_permission_manager/BUILD.gn b/frameworks/ets/ani/uri_permission_manager/BUILD.gn index ea9f3d4ec41bd54ab2ae07a36eb3264930aa766f..d4f9f077755667574d849cd31a265308574a3256 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 1bf1b8ec940a0fdd720ed9d081f6fc7f9b2c9c95..2d57e00c5c60e5e7289b72477d5d3fff0c7eceac 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 diff --git a/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp b/frameworks/ets/ani/wantagent/src/ani_want_agent.cpp index db2bd736cdb498b664f476b45ce67f802136eccc..ce4634f7dcfc1c641bc828821b3399c3e82c7d50 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/application/AutoFillType.ets b/frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets similarity index 41% rename from frameworks/ets/ets/application/AutoFillType.ets rename to frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets index 122dee5a1757cf9baf614f7b192dfdb0573ed26c..b238c15ea6a2ee9f02c7459e07fc5f3aac73baa9 100644 --- a/frameworks/ets/ets/application/AutoFillType.ets +++ b/frameworks/ets/ets/@ohos.app.ability.ShareExtensionAbility.ets @@ -13,39 +13,7 @@ * 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 +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/@ohos.app.ability.Want.ets b/frameworks/ets/ets/@ohos.app.ability.Want.ets index 3d0cbd3d0084e838af8d128476217b44c9005d6c..6d7c75b3136927fa3172a881542c1cad61e42102 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 ''; diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index efa1a659ad3f98ab041fa7a17a09a4533ca3ae5c..f2f3bae1174adb5424dad06b74be462e806e10e6 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 = "./" @@ -1192,6 +1177,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 = [ @@ -1221,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", @@ -1244,6 +1244,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 +1261,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 3b59dc77f22b2079015e75cd6d491a6fe013241c..e67cae97100de2c0744896f9ad3c786623b84109 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/ServiceExtensionContext.ets b/frameworks/ets/ets/application/ServiceExtensionContext.ets index 569ada6a428f75c37d5c3aab5118723b92eff2bf..2bb11c2f1f5b3dce31fec9f54417d783ffca9de5 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 4be5cc5c242fe2446d165fe76303de52f4b82d27..0d629d1c62ce39846a7fffbc7dfe1177a52f8457 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 79037510d55ead8f91d1626512d61cc1de093acb..fc684e9764fbdff81c3f0091179c498233cd452a 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); @@ -122,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) { @@ -132,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); }); }); } @@ -177,8 +186,8 @@ export default class UIExtensionContext extends ExtensionContext { }); } - 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) => { @@ -189,27 +198,21 @@ export default class UIExtensionContext extends ExtensionContext { } }); taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, 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; } - 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); - } else { - reject(err); - } - }); - taskpool.execute((): void => { - this.nativeStartAbilityForResult(want, startOptions, myCall); - }); + reportDrawnCompleted(callback: AsyncCallback): void { + let myCall = new AsyncCallbackWrapper(callback); + taskpool.execute((): void => { + this.nativeReportDrawnCompleted(myCall); }); - return p; } } \ No newline at end of file diff --git a/frameworks/ets/ets/wantAgent/wantAgentInfo.ets b/frameworks/ets/ets/wantAgent/wantAgentInfo.ets index 4487de50bf145688935b710e64e187b6945c5da6..ae0859b67e6277702c3db0851607ee2f8e7d8b46 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; diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index cbfe81f15f92f010dd4c8dc71418c36e3932a573..b4759c3826c7336da6e84f1dad60aa2b35349a09 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", diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index e5ceb9110c429634d075e3e17ec81f9af2407e25..545d5c42098730e8281c20e3b781f12c90b8ca7f 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 e5c0886feaa019a06ce205c2f9933e4ae92a410d..98ed7221404c4a20b535adcaf28fc1695f16e051 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 0a0bd6ebd28bd15cb860b2cfb263ff251d6342c6..721d67dd6e24e90edefd928dd922eff0c99aa698 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/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 094865db94b11396042b54301ed39a22bd52336d..04856f7ea156e3f1d2f68ff7ccfac0910a98c675 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); 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 8c9c1a0363bc0370e16c5dfedda1b8691c961409..093ecb4fc16e6992fbabde7ffa1b35d4b7bf30cc 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 709cca198469e7e10a8adf232458cb9c80a764e0..07f8a6615e3ebdde1b5e4874885a9a03fc98b834 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",