diff --git a/frameworks/ets/ani/service_extension_ability/include/ets_service_extension.h b/frameworks/ets/ani/service_extension_ability/include/ets_service_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..a148c2bf2eeb22f5a7ba8e39d732bfa7f7de4556 --- /dev/null +++ b/frameworks/ets/ani/service_extension_ability/include/ets_service_extension.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_ABILITY_RUNTIME_ETS_SERVICE_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_ETS_SERVICE_EXTENSION_H + +#include "configuration.h" +#include "ets_runtime.h" +#include "service_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @brief Basic service components. + */ +class EtsServiceExtension : public ServiceExtension { +public: + explicit EtsServiceExtension(ETSRuntime &etsRuntime); + virtual ~EtsServiceExtension() override; + + /** + * @brief Create EtsServiceExtension. + * + * @param runtime The runtime. + * @return The EtsServiceExtension instance. + */ + static EtsServiceExtension *Create(const std::unique_ptr &runtime); + + /** + * @brief Init the extension. + * + * @param record the extension record. + * @param application the application info. + * @param handler the extension handler. + * @param token the remote token. + */ + virtual void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, const sptr &token) override; + + /** + * @brief Called when this extension is started. You must override this function if you want to perform some + * initialization operations during extension startup. + * + * This function can be called only once in the entire lifecycle of an extension. + * @param Want Indicates the {@link Want} structure containing startup information about the extension. + */ + virtual void OnStart(const AAFwk::Want &want) override; + + /** + * @brief Called when this Service extension is connected for the first time. + * + * You can override this function to implement your own processing logic. + * + * @param want Indicates the {@link Want} structure containing connection information about the Service extension. + * @return Returns a pointer to the sid of the connected Service extension. + */ + virtual sptr OnConnect(const AAFwk::Want &want) override; + + /** + * @brief Called when this Service extension is connected for the first time. + * + * You can override this function to implement your own processing logic. + * + * @param want Indicates the {@link Want} structure containing connection information about the Service extension. + * @param callbackInfo Indicates the lifecycle transaction callback information + * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback + * @return Returns a pointer to the sid of the connected Service extension. + */ + virtual sptr OnConnect(const AAFwk::Want &want, + AppExecFwk::AbilityTransactionCallbackInfo> *callbackInfo, bool &isAsyncCallback) override; + + /** + * @brief Called when all abilities connected to this Service extension are disconnected. + * + * You can override this function to implement your own processing logic. + * + */ + virtual void OnDisconnect(const AAFwk::Want &want) override; + + /** + * @brief Called when all abilities connected to this Service extension are disconnected. + * + * You can override this function to implement your own processing logic. + * @param callbackInfo Indicates the lifecycle transaction callback information + * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback + */ + void OnDisconnect(const AAFwk::Want &want, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, + bool &isAsyncCallback) override; + + /** + * @brief Called back when Service is started. + * This method can be called only by Service. You can use the StartAbility(ohos.aafwk.content.Want) method to start + * Service. Then the system calls back the current method to use the transferred want parameter to execute its own + * logic. + * + * @param want Indicates the want of Service to start. + * @param restart Indicates the startup mode. The value true indicates that Service is restarted after being + * destroyed, and the value false indicates a normal startup. + * @param startId Indicates the number of times the Service extension has been started. The startId is incremented + * by 1 every time the extension is started. For example, if the extension has been started for six times, the + * value of startId is 6. + */ + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; + + /** + * @brief Called when this extension enters the STATE_STOP state. + * + * The extension in the STATE_STOP is being destroyed. + * You can override this function to implement your own processing logic. + */ + virtual void OnStop() override; + + /** + * @brief Called when the system configuration is updated. + * + * @param configuration Indicates the updated configuration information. + */ + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; + + /** + * @brief Called when extension need dump info. + * + * @param params The params from service. + * @param info The dump info to show. + */ + virtual void Dump(const std::vector ¶ms, std::vector &info) override; + +private: + void ConfigurationUpdated(); + ani_ref CallObjectMethod(bool withResult, const char *name, const char *signature, ...); + + ETSRuntime &etsRuntime_; + std::unique_ptr etsObj_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_SERVICE_EXTENSION_H \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..a6e97772b8c4540b6b83ec82664369b065fa1aa0 --- /dev/null +++ b/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp @@ -0,0 +1,387 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ets_service_extension.h" + +#include "ability_info.h" +#include "ability_manager_client.h" +#include "ani_common_want.h" +#include "ani_remote_object.h" +#include "configuration_utils.h" +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "js_service_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; +namespace { +constexpr const char *CLASSNAME_SERVICE_ABILITY = + "L@ohos/app/ability/ServiceExtensionAbility/ServiceExtensionAbility;"; +constexpr const char *NATIVE_ONCONNECT_CALLBACK_SIGNATURE = "L@ohos/rpc/rpc/RemoteObject;:Z"; +constexpr const char *ON_CREATE_SIGNATURE = "L@ohos/app/ability/Want/Want;:V"; +constexpr const char *VOID_SIGNATURE = ":V"; +constexpr const char *ON_CONNECT_SIGNATURE = "L@ohos/app/ability/Want/Want;:Lstd/core/Object;"; +constexpr const char *CHECK_PROMISE_SIGNATURE = "Lstd/core/Object;:Z"; +constexpr const char *CALL_PROMISE_SIGNATURE = "Lstd/core/Object;:Z"; +constexpr const char *ON_DISCONNECT_SIGNATURE = "L@ohos/app/ability/Want/Want;:V"; +constexpr const char *ON_REQUEST_SIGNATURE = "L@ohos/app/ability/Want/Want;D:V"; + +void DisconnectPromiseCallback(ani_env *env, ani_object aniObj) +{ + TAG_LOGD(AAFwkTag::SERVICE_EXT, "DisconnectPromiseCallback"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + ani_long disconnectCallbackPoint = 0; + ani_status status = ANI_ERROR; + if ((status = env->Object_GetFieldByName_Long(aniObj, "disconnectCallbackPoint", &disconnectCallbackPoint)) != + ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + return; + } + auto *callbackInfo = reinterpret_cast *>(disconnectCallbackPoint); + if (callbackInfo == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null callbackInfo"); + return; + } + callbackInfo->Call(); + AppExecFwk::AbilityTransactionCallbackInfo<>::Destroy(callbackInfo); +} + +void ConnectPromiseCallback(ani_env *env, ani_object aniObj, ani_object obj) +{ + TAG_LOGD(AAFwkTag::SERVICE_EXT, "ConnectPromiseCallback"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + ani_long connectCallbackPoint = 0; + ani_status status = ANI_ERROR; + if ((status = env->Object_GetFieldByName_Long(aniObj, "connectCallbackPoint", &connectCallbackPoint)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + return; + } + auto remoteObject = AniGetNativeRemoteObject(env, obj); + if (remoteObject == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null remoteObject"); + } + auto *callbackInfo = + reinterpret_cast> *>(connectCallbackPoint); + if (callbackInfo == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null callbackInfo"); + return; + } + + callbackInfo->Call(remoteObject); + AppExecFwk::AbilityTransactionCallbackInfo>::Destroy(callbackInfo); +} +} // namespace + +EtsServiceExtension *EtsServiceExtension::Create(const std::unique_ptr &runtime) +{ + return new EtsServiceExtension(static_cast(*runtime)); +} + +EtsServiceExtension::EtsServiceExtension(ETSRuntime &etsRuntime) : etsRuntime_(etsRuntime) {} +EtsServiceExtension::~EtsServiceExtension() +{ + TAG_LOGD(AAFwkTag::SERVICE_EXT, "EtsServiceExtension destory"); + auto context = GetContext(); + if (context) { + context->Unbind(); + } +} + +void EtsServiceExtension::Init(const std::shared_ptr &record, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + TAG_LOGD(AAFwkTag::SERVICE_EXT, "EtsServiceExtension init"); + if ((token == nullptr) || (application == nullptr) || (handler == nullptr) || (record == nullptr)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "init failed, some obj null"); + return; + } + Extension::Init(record, application, handler, token); + if (Extension::abilityInfo_ == nullptr || Extension::abilityInfo_->srcEntrance.empty()) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "EtsServiceExtension Init abilityInfo error"); + return; + } + std::string srcPath(Extension::abilityInfo_->moduleName + "/"); + srcPath.append(Extension::abilityInfo_->srcEntrance); + auto pos = srcPath.rfind("."); + if (pos != std::string::npos) { + srcPath.erase(pos); + srcPath.append(".abc"); + } + std::string moduleName(Extension::abilityInfo_->moduleName); + moduleName.append("::").append(abilityInfo_->name); + etsObj_ = etsRuntime_.LoadModule(moduleName, srcPath, abilityInfo_->hapPath, + abilityInfo_->compileMode == AppExecFwk::CompileMode::ES_MODULE, false, abilityInfo_->srcEntrance); + if (etsObj_ == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null etsObj"); + return; + } + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + std::array functions = { + ani_native_function { + "nativeOnDisconnectCallback", VOID_SIGNATURE, reinterpret_cast(DisconnectPromiseCallback) }, + ani_native_function { "nativeOnConnectCallback", NATIVE_ONCONNECT_CALLBACK_SIGNATURE, + reinterpret_cast(ConnectPromiseCallback) }, + }; + ani_class cls = nullptr; + ani_status status = ANI_ERROR; + if ((status = env->FindClass(CLASSNAME_SERVICE_ABILITY, &cls)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status: %{public}d", status); + return; + } + if ((status = env->Class_BindNativeMethods(cls, functions.data(), functions.size())) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "Class_BindNativeMethods is fail %{public}d", status); + return; + } +} + +void EtsServiceExtension::OnStart(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnStart"); + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "env not found Ability.ets"); + return; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return; + } + + CallObjectMethod(false, "onCreate", ON_CREATE_SIGNATURE, wantRef); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); +} + +void EtsServiceExtension::OnStop() +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnStop"); + ServiceExtension::OnStop(); + CallObjectMethod(false, "onDestroy", VOID_SIGNATURE); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); +} + +sptr EtsServiceExtension::OnConnect(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnConnect"); + Extension::OnConnect(want); + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return nullptr; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return nullptr; + } + ani_ref result = CallObjectMethod(true, "onConnect", ON_CONNECT_SIGNATURE, wantRef); + auto obj = reinterpret_cast(result); + auto remoteObj = AniGetNativeRemoteObject(env, obj); + if (remoteObj == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "remoteObj null"); + return nullptr; + } + TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); + return remoteObj; +} + +sptr EtsServiceExtension::OnConnect(const AAFwk::Want &want, + AppExecFwk::AbilityTransactionCallbackInfo> *callbackInfo, bool &isAsyncCallback) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnConnect"); + Extension::OnConnect(want); + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return nullptr; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return nullptr; + } + ani_long connectCallbackPoint = (ani_long)callbackInfo; + ani_status status = ANI_ERROR; + ani_field callbackField = nullptr; + if ((status = env->Class_FindField(etsObj_->aniCls, "connectCallbackPoint", &callbackField)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + if ((status = env->Object_SetField_Long(etsObj_->aniObj, callbackField, connectCallbackPoint)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + ani_ref aniRemoteRef = CallObjectMethod(true, "onConnect", ON_CONNECT_SIGNATURE, wantRef); + auto aniRemoteobj = reinterpret_cast(aniRemoteRef); + ani_method method {}; + if ((status = env->Class_FindMethod(etsObj_->aniCls, "checkPromise", CHECK_PROMISE_SIGNATURE, &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + ani_boolean isPromise = false; + if ((status = env->Object_CallMethod_Boolean(etsObj_->aniObj, method, &isPromise, aniRemoteobj)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + if (!isPromise) { + isAsyncCallback = false; + auto remoteObj = AniGetNativeRemoteObject(env, aniRemoteobj); + if (remoteObj == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null remoteObj"); + } + return remoteObj; + } + if ((status = env->Class_FindMethod(etsObj_->aniCls, "callPromise", CALL_PROMISE_SIGNATURE, &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + ani_boolean callResult = false; + if ((status = env->Object_CallMethod_Boolean(etsObj_->aniObj, method, &callResult, aniRemoteobj)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return nullptr; + } + isAsyncCallback = callResult; + return nullptr; +} + +void EtsServiceExtension::OnDisconnect(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnDisconnect"); + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return; + } + CallObjectMethod(false, "onDisconnect", ON_DISCONNECT_SIGNATURE, wantRef); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); +} + +void EtsServiceExtension::OnDisconnect( + const AAFwk::Want &want, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnDisconnect"); + auto env = etsRuntime_.GetAniEnv(); + if (env) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return; + } + if (callbackInfo == nullptr) { + isAsyncCallback = false; + OnDisconnect(want); + return; + } + ani_long disconnectCallbackPoint = (ani_long)callbackInfo; + ani_status status = ANI_ERROR; + ani_field field = nullptr; + if ((status = env->Class_FindField(etsObj_->aniCls, "disconnectCallbackPoint", &field)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return; + } + if ((status = env->Object_SetField_Long(etsObj_->aniObj, field, disconnectCallbackPoint)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UIABILITY, "status : %{public}d", status); + return; + } + CallObjectMethod(false, "callOnDisconnect", ON_DISCONNECT_SIGNATURE, wantRef); +} + +void EtsServiceExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnCommand"); + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return; + } + ani_ref wantRef = OHOS::AppExecFwk::WrapWant(env, want); + if (wantRef == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null wantRef"); + return; + } + ani_int iStartId = static_cast(startId); + CallObjectMethod(false, "onRequest", ON_REQUEST_SIGNATURE, wantRef, iStartId); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "end"); + return; +} + +ani_ref EtsServiceExtension::CallObjectMethod(bool withResult, const char *name, const char *signature, ...) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, std::string("CallObjectMethod:") + name); + ani_status status = ANI_ERROR; + ani_method method = nullptr; + auto env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "null env"); + return nullptr; + } + if ((status = env->Class_FindMethod(etsObj_->aniCls, name, signature, &method)) != ANI_OK) { + return nullptr; + } + if (method == nullptr) { + return nullptr; + } + ani_ref res = nullptr; + va_list args; + if (withResult) { + va_start(args, signature); + if ((status = env->Object_CallMethod_Ref_V(etsObj_->aniObj, method, &res, args)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + return nullptr; + } + va_end(args); + return res; + } + va_start(args, signature); + if ((status = env->Object_CallMethod_Void_V(etsObj_->aniObj, method, args)) != ANI_OK) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "status : %{public}d", status); + } + va_end(args); + return nullptr; +} +void EtsServiceExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) {} + +void EtsServiceExtension::ConfigurationUpdated() {} + +void EtsServiceExtension::Dump(const std::vector ¶ms, std::vector &info) {} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ets/@ohos.app.ability.ServiceExtensionAbility.ets b/frameworks/ets/ets/@ohos.app.ability.ServiceExtensionAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c17298b63ebf2e620d569f7140218d4929ee888b --- /dev/null +++ b/frameworks/ets/ets/@ohos.app.ability.ServiceExtensionAbility.ets @@ -0,0 +1,97 @@ +/* + * 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 rpc from '@ohos.rpc'; +import Want from '@ohos.app.ability.Want'; +import ServiceExtensionContext from 'application.ServiceExtensionContext'; +import { Configuration } from '@ohos.app.ability.Configuration' +import hilog from '@ohos.hilog'; + +class MyService extends rpc.RemoteObject { + constructor(descriptor: string) { + super(descriptor); + } + + public onRemoteMessageRequest( + code: number, + data: rpc.MessageSequence, + reply: rpc.MessageSequence, + options: rpc.MessageOption + ): boolean | Promise { + return false; + } +} + +export default class ServiceExtensionAbility { + private connectCallbackPoint: long; + + private native nativeOnConnectCallback(service: rpc.RemoteObject): boolean; + + private checkPromise(obj: NullishType): boolean { + if (obj instanceof Promise) { + return true; + } + return false; + } + + private callPromise(p: Promise): boolean { + let remoteObj: rpc.RemoteObject = await p; + return this.nativeOnConnectCallback(remoteObj); + } + + private isOnDisconnectAsync: boolean = true; + private disconnectCallbackPoint: long; + + private native nativeOnDisconnectCallback(): void; + + private callOnDisconnect(want: Want): void { + let p = this.onDisconnectAsync(want); + if (this.isOnDisconnectAsync) { + p.then((a: undefined): void => { + this.nativeOnDisconnectCallback(); + }); + } else { + this.onDisconnect(want); + } + } + + launchWant: Want = new Want(); + lastRequestWant: Want = new Want(); + context: ServiceExtensionContext = {}; + + onCreate(want: Want): void { + } + + onDestroy(): void { + } + + onRequest(want: Want, startld: double): void { + } + + onConnect(want: Want): rpc.RemoteObject | Promise { + let myService: rpc.RemoteObject = new MyService("onConnect"); + return myService; + } + + onDisconnect(want: Want): void { + } + + onDisconnectAsync(want: Want): Promise { + console.log("onDisconnectAsync"); + this.isOnDisconnectAsync = false; + return new Promise((resolve: (a: undefined) => void, reject: (err: Error) => void): void => { + }); + } +} \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 9f07fdb1852acb6b8a7f2fdd8836c92349d787e4..d5228bc029381f9998e318bf18c5725415f23b7c 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -111,6 +111,42 @@ ohos_prebuilt_etc("ability_runtime_want_constant_abc_etc") { deps = [ ":ability_runtime_want_constant_abc" ] } +generate_static_abc("service_extension_ability") { + base_url = "./" + files = [ + "./@ohos.app.ability.ServiceExtensionAbility.ets", + "./application/ServiceExtensionContext.ets", + ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/service_extension_ability.abc" +} + +ohos_prebuilt_etc("service_extension_ability_abc_etc") { + source = "$target_out_dir/service_extension_ability.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":service_extension_ability" ] +} + +generate_static_abc("ability_runtime_extension_context_abc") { + base_url = "./" + files = [ "./application/ExtensionContext.ets" ] + + is_boot_abc = "True" + device_dst_file = + "/system/framework/ability_runtime_extension_context_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_extension_context_abc_etc") { + source = "$target_out_dir/ability_runtime_extension_context_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_extension_context_abc" ] +} + group("ets_packages") { deps = [ ":ability_runtime_ability_constant_abc_etc", @@ -119,5 +155,7 @@ group("ets_packages") { ":ability_runtime_start_options_abc_etc", ":ability_runtime_want_abc_etc", ":ability_runtime_want_constant_abc_etc", + ":service_extension_ability_abc_etc", + ":ability_runtime_extension_context_abc_etc", ] } diff --git a/frameworks/ets/ets/application/ExtensionContext.ets b/frameworks/ets/ets/application/ExtensionContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d46b66d2add1dcda7e2c90ec98db4ac75b47931 --- /dev/null +++ b/frameworks/ets/ets/application/ExtensionContext.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Context from 'application.Context' +import {ExtensionAbilityInfo} from 'bundleManager.ExtensionAbilityInfo' + +export default class ExtensionContext extends Context { + extensionAbilityInfo: ExtensionAbilityInfo; + native constructor(); + constructor(extensionAbilityInfo: ExtensionAbilityInfo) { + super(); + this.extensionAbilityInfo = extensionAbilityInfo; + } +} \ No newline at end of file diff --git a/frameworks/ets/ets/application/ServiceExtensionContext.ets b/frameworks/ets/ets/application/ServiceExtensionContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c9fe395ffa688932f94de366ebf8313b90d9514 --- /dev/null +++ b/frameworks/ets/ets/application/ServiceExtensionContext.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 ExtensionContext from 'application.ExtensionContext' + +export default class ServiceExtensionContext extends ExtensionContext { + +} \ No newline at end of file diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index e4f5a06ba62307af4ddfb2c27d0920d222498807..e9212cdc826af854ad38aaf19484ad4f286742af 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -59,6 +59,7 @@ ohos_shared_library("ability_context_native") { "ability_runtime/connection_manager.cpp", "ability_runtime/dialog_request_callback_impl.cpp", "ability_runtime/dialog_ui_extension_callback.cpp", + "ability_runtime/ets_extension_context.cpp", "ability_runtime/js_extension_context.cpp", "ability_runtime/local_call_container.cpp", "ability_runtime/local_call_record.cpp", @@ -92,6 +93,8 @@ ohos_shared_library("ability_context_native") { "image_framework:image_native", "ipc:ipc_core", "napi:ace_napi", + "runtime_core:ani", + "bundle_framework:bms_ani_common", ] public_external_deps = [ "ability_base:extractortool", diff --git a/frameworks/native/ability/ability_runtime/ets_extension_context.cpp b/frameworks/native/ability/ability_runtime/ets_extension_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cdeb556cd9cdf56b998c5209175e334b012cc624 --- /dev/null +++ b/frameworks/native/ability/ability_runtime/ets_extension_context.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ets_extension_context.h" + +#include "common_fun_ani.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { + +bool SetExtensionAbilityInfo(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, + std::shared_ptr context, std::shared_ptr abilityInfo) +{ + bool iRet = false; + if (aniEnv == nullptr || context == nullptr || abilityInfo == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "aniEnv or context or abilityInfo is nullptr"); + return iRet; + } + auto hapModuleInfo = context->GetHapModuleInfo(); + ani_status status = ANI_OK; + if (abilityInfo && hapModuleInfo) { + auto isExist = [&abilityInfo](const AppExecFwk::ExtensionAbilityInfo &info) { + TAG_LOGD(AAFwkTag::CONTEXT, "%{public}s, %{public}s", info.bundleName.c_str(), info.name.c_str()); + return info.bundleName == abilityInfo->bundleName && info.name == abilityInfo->name; + }; + auto infoIter = + std::find_if(hapModuleInfo->extensionInfos.begin(), hapModuleInfo->extensionInfos.end(), isExist); + if (infoIter == hapModuleInfo->extensionInfos.end()) { + TAG_LOGE(AAFwkTag::CONTEXT, "set extensionAbilityInfo fail"); + return iRet; + } + ani_field extensionAbilityInfoField; + status = aniEnv->Class_FindField(contextClass, "extensionAbilityInfo", &extensionAbilityInfoField); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status); + return iRet; + } + ani_object extAbilityInfoObj = AppExecFwk::CommonFunAni::ConvertExtensionInfo(aniEnv, *infoIter); + status = aniEnv->Object_SetField_Ref( + contextObj, extensionAbilityInfoField, reinterpret_cast(extAbilityInfoObj)); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status); + return iRet; + } + iRet = true; + } + return iRet; +} + +void CreatEtsExtensionContext(ani_env *aniEnv, ani_class contextClass, ani_object contextObj, + std::shared_ptr context, std::shared_ptr abilityInfo) +{ + TAG_LOGD(AAFwkTag::CONTEXT, "CreatEtsExtensionContext Call"); + if (aniEnv == nullptr || context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "aniEnv or context is nullptr"); + return; + } + + if (!SetExtensionAbilityInfo(aniEnv, contextClass, contextObj, context, abilityInfo)) { + TAG_LOGE(AAFwkTag::CONTEXT, "SetExtensionAbilityInfo fail"); + return; + } +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 52d727221b7f227bb5bed8c59e3ca21fceff1a4d..23311d3293f0199976ff1153fb12f33ca249782a 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -155,6 +155,7 @@ ohos_shared_library("abilitykit_utils") { "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/runtime/include", "${ability_runtime_innerkits_path}/wantagent/include", "${ability_runtime_services_path}/abilitymgr/include/utils", "${ability_runtime_services_path}/abilitymgr/include", @@ -1112,6 +1113,8 @@ ohos_shared_library("service_extension") { defines = [ "AMS_LOG_TAG = \"Ability\"" ] defines += [ "AMS_LOG_DOMAIN = 0xD001300" ] include_dirs = [ + "${ability_runtime_path}/frameworks/ets/ani/ani_common/include", + "${ability_runtime_path}/frameworks/ets/ani/service_extension_ability/include", "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime", "${ability_runtime_path}/utils/global/freeze/include", @@ -1122,6 +1125,7 @@ ohos_shared_library("service_extension") { "${ability_runtime_native_path}/ability/native/js_service_extension_context.cpp", "${ability_runtime_native_path}/ability/native/service_extension.cpp", "${ability_runtime_native_path}/appkit/ability_runtime/service_extension_context.cpp", + "${ability_runtime_path}/frameworks/ets/ani/service_extension_ability/src/ets_service_extension.cpp", ] deps = [ @@ -1138,6 +1142,7 @@ ohos_shared_library("service_extension") { "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext", "${ability_runtime_path}/utils/global/freeze:freeze_util", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", ] external_deps = [ @@ -1151,7 +1156,9 @@ ohos_shared_library("service_extension") { "hitrace:hitrace_meter", "ipc:ipc_core", "ipc:ipc_napi", + "ipc:rpc_ani", "napi:ace_napi", + "runtime_core:ani", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/frameworks/native/ability/native/ability_loader.cpp b/frameworks/native/ability/native/ability_loader.cpp index 1c26bd9c57a4b15d9a00a68a3e7fae84e03eb1b1..1a8f740a1c2e2bef0216900f7cb276eea9397081 100644 --- a/frameworks/native/ability/native/ability_loader.cpp +++ b/frameworks/native/ability/native/ability_loader.cpp @@ -52,21 +52,23 @@ Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName) return nullptr; } -AbilityRuntime::Extension *AbilityLoader::GetExtensionByName(const std::string &abilityName) +AbilityRuntime::Extension *AbilityLoader::GetExtensionByName(const std::string &abilityName, + const std::string &language) { auto it = extensions_.find(abilityName); if (it != extensions_.end()) { - return it->second(); + return it->second(language); } TAG_LOGE(AAFwkTag::ABILITY, "failed:%{public}s", abilityName.c_str()); return nullptr; } -AbilityRuntime::UIAbility *AbilityLoader::GetUIAbilityByName(const std::string &abilityName) +AbilityRuntime::UIAbility *AbilityLoader::GetUIAbilityByName(const std::string &abilityName, + const std::string &language) { auto it = uiAbilities_.find(abilityName); if (it != uiAbilities_.end()) { - return it->second(); + return it->second(language); } TAG_LOGE(AAFwkTag::ABILITY, "failed:%{public}s", abilityName.c_str()); return nullptr; diff --git a/frameworks/native/ability/native/extension_ability_thread.cpp b/frameworks/native/ability/native/extension_ability_thread.cpp index f72fa0f4c2a0baf0747fcde775a4cb4ec02b887a..6a7633b35194a6998d9e00c87f75cf097d648bd9 100644 --- a/frameworks/native/ability/native/extension_ability_thread.cpp +++ b/frameworks/native/ability/native/extension_ability_thread.cpp @@ -242,7 +242,13 @@ void ExtensionAbilityThread::HandleAttach(const std::shared_ptr abilityInfo = abilityRecord->GetAbilityInfo(); + if (abilityInfo == nullptr) { + TAG_LOGE(AAFwkTag::EXT, "null abilityInfo"); + return; + } + auto extension = AppExecFwk::AbilityLoader::GetInstance().GetExtensionByName(abilityName, + abilityInfo->codeLanguage); if (extension == nullptr) { TAG_LOGE(AAFwkTag::EXT, "null extension"); return; diff --git a/frameworks/native/ability/native/service_extension.cpp b/frameworks/native/ability/native/service_extension.cpp index 0838b03f9aa3437b08bcb5bc1047d4e7b1c0d9df..cbf2ad871c835fa25d94949c6befee59f818e352 100644 --- a/frameworks/native/ability/native/service_extension.cpp +++ b/frameworks/native/ability/native/service_extension.cpp @@ -21,6 +21,7 @@ #include "js_service_extension.h" #include "runtime.h" #include "service_extension_context.h" +#include "ets_service_extension.h" namespace OHOS { namespace AbilityRuntime { @@ -46,7 +47,8 @@ ServiceExtension* ServiceExtension::Create(const std::unique_ptr& runti switch (runtime->GetLanguage()) { case Runtime::Language::JS: return JsServiceExtension::Create(runtime); - + case Runtime::Language::ETS: + return EtsServiceExtension::Create(runtime); default: return new ServiceExtension(); } diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index 18d97dee4d6e877cd0b78765fd3c7611c0128c44..e20643c444024976ee2d7b3daff98bc6a6239792 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -131,7 +131,8 @@ void UIAbilityThread::Attach(const std::shared_ptr } // 2.new ability - auto ability = AppExecFwk::AbilityLoader::GetInstance().GetUIAbilityByName(abilityName); + auto ability = AppExecFwk::AbilityLoader::GetInstance().GetUIAbilityByName( + abilityName, abilityRecord->GetAbilityInfo()->codeLanguage); if (ability == nullptr) { TAG_LOGE(AAFwkTag::UIABILITY, "null ability"); return; @@ -203,7 +204,8 @@ void UIAbilityThread::Attach(const std::shared_ptr } // 2.new ability - auto ability = AppExecFwk::AbilityLoader::GetInstance().GetUIAbilityByName(abilityName); + auto ability = AppExecFwk::AbilityLoader::GetInstance().GetUIAbilityByName( + abilityName, abilityRecord->GetAbilityInfo()->codeLanguage); if (ability == nullptr) { TAG_LOGE(AAFwkTag::UIABILITY, "null ability"); return; diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index cc0227d2feb3217aad08944d7a2786747cca7d8b..11863d7b8bd13c71b1da20dcdbd81cfc737d3765 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -54,6 +54,7 @@ config("appkit_config") { config("appkit_public_config") { visibility = [ ":*" ] include_dirs = [ + "${ability_runtime_path}/ets_environment/interfaces/inner_api", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_delegator", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", @@ -75,6 +76,7 @@ config("appkit_public_config") { ohos_shared_library("appkit_native") { include_dirs = [ "native", + "${ability_runtime_path}/ets_environment/interfaces/inner_api", "${ability_runtime_path}/interfaces/inner_api/error_utils/include", "${ability_runtime_path}/interfaces/kits/native/appkit", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", @@ -166,6 +168,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/ets_environment/frameworks/ets_environment:ets_environment", "${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_services_path}/common:app_util", @@ -208,6 +211,7 @@ ohos_shared_library("appkit_native") { "napi:ace_napi", "preferences:native_preferences", "resource_management:global_resmgr", + "runtime_core:ani", "safwk:system_ability_fwk", "samgr:samgr_proxy", "storage_service:storage_manager_acl", diff --git a/frameworks/native/appkit/ability_delegator/ability_delegator_registry.cpp b/frameworks/native/appkit/ability_delegator/ability_delegator_registry.cpp index 7187c88382eac76eabb85137bf793722dba009b7..bfdc3298b9acaca3b9adde777785904821b8e810 100644 --- a/frameworks/native/appkit/ability_delegator/ability_delegator_registry.cpp +++ b/frameworks/native/appkit/ability_delegator/ability_delegator_registry.cpp @@ -17,20 +17,30 @@ namespace OHOS { namespace AppExecFwk { -std::shared_ptr AbilityDelegatorRegistry::abilityDelegator_ {}; +std::map> + AbilityDelegatorRegistry::abilityDelegator_ {}; std::shared_ptr AbilityDelegatorRegistry::abilityDelegatorArgs_ {}; -std::shared_ptr AbilityDelegatorRegistry::GetAbilityDelegator() +std::shared_ptr AbilityDelegatorRegistry::GetAbilityDelegator( + const AbilityRuntime::Runtime::Language &language) { - auto p = reinterpret_cast(abilityDelegator_.get()); - return std::shared_ptr(abilityDelegator_, p); + auto it = abilityDelegator_.find(language); + if (it != abilityDelegator_.end()) { + auto p = reinterpret_cast(it->second.get()); + return std::shared_ptr(it->second, p); + } + return nullptr; } #ifdef CJ_FRONTEND std::shared_ptr AbilityDelegatorRegistry::GetCJAbilityDelegator() { - auto p = reinterpret_cast(abilityDelegator_.get()); - return std::shared_ptr(abilityDelegator_, p); + auto it = abilityDelegator_.find(AbilityRuntime::Runtime::Language::CJ); + if (it != abilityDelegator_.end()) { + auto p = reinterpret_cast(it->second.get()); + return std::shared_ptr(it->second, p); + } + return nullptr; } #endif @@ -39,11 +49,11 @@ std::shared_ptr AbilityDelegatorRegistry::GetArguments() return abilityDelegatorArgs_; } -void AbilityDelegatorRegistry::RegisterInstance( - const std::shared_ptr& delegator, const std::shared_ptr& args) +void AbilityDelegatorRegistry::RegisterInstance(const std::shared_ptr &delegator, + const std::shared_ptr &args, const AbilityRuntime::Runtime::Language &language) { - abilityDelegator_ = delegator; abilityDelegatorArgs_ = args; + abilityDelegator_.insert_or_assign(language, delegator); } } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/appkit/app/application_data_manager.cpp b/frameworks/native/appkit/app/application_data_manager.cpp index 6dfd3a4493efb0896184c21819410ade2e088f11..79c2449ccbffee933660e96284a27195137eed92 100644 --- a/frameworks/native/appkit/app/application_data_manager.cpp +++ b/frameworks/native/appkit/app/application_data_manager.cpp @@ -59,6 +59,15 @@ bool ApplicationDataManager::NotifyCJUnhandledException(const std::string &errMs return AppRecovery::GetInstance().TryRecoverApp(StateReason::CJ_ERROR); } +bool ApplicationDataManager::NotifyETSUnhandledException(const std::string &errMsg) +{ + if (errorObserver_) { + errorObserver_->OnUnhandledException(errMsg); + return true; + } + return AppRecovery::GetInstance().TryRecoverApp(StateReason::JS_ERROR); +} + void ApplicationDataManager::RemoveErrorObserver() { errorObserver_ = nullptr; @@ -88,5 +97,15 @@ bool ApplicationDataManager::NotifyCJExceptionObject(const AppExecFwk::ErrorObje // and restart as developer wants return AppRecovery::GetInstance().TryRecoverApp(StateReason::CJ_ERROR); } + +bool ApplicationDataManager::NotifyETSExceptionObject(const AppExecFwk::ErrorObject &errorObj) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Notify Exception error observer come"); + if (errorObserver_) { + errorObserver_->OnExceptionObject(errorObj); + return true; + } + return AppRecovery::GetInstance().TryRecoverApp(StateReason::JS_ERROR); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/appkit/app/dump_runtime_helper.cpp b/frameworks/native/appkit/app/dump_runtime_helper.cpp index 945867d5b91541371d8a8ae7eef1c18f45e61cac..052ec4ece780ccf21afa532700a9d370de81a831 100644 --- a/frameworks/native/appkit/app/dump_runtime_helper.cpp +++ b/frameworks/native/appkit/app/dump_runtime_helper.cpp @@ -87,7 +87,7 @@ void DumpRuntimeHelper::SetAppFreezeFilterCallback() TAG_LOGE(AAFwkTag::APPKIT, "null application"); return; } - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -205,7 +205,7 @@ void DumpRuntimeHelper::DumpJsHeap(const OHOS::AppExecFwk::JsHeapDumpInfo &info) TAG_LOGE(AAFwkTag::APPKIT, "null application"); return; } - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -235,7 +235,7 @@ void DumpRuntimeHelper::DumpCjHeap(const OHOS::AppExecFwk::CjHeapDumpInfo &info) TAG_LOGE(AAFwkTag::APPKIT, "null application"); return; } - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 0e856912f1bd7f5d2355dc5da48545bda731cea6..d15795546b2c7c7ad358189fdc271dbeef3b2505 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -75,6 +75,7 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "js_runtime.h" +#include "ets_runtime.h" #ifdef CJ_FRONTEND #include "cj_runtime.h" #endif @@ -183,6 +184,7 @@ const char* PC_LIBRARY_PATH = "/system/lib64/liblayered_parameters_manager.z.so" const char* PC_FUNC_INFO = "DetermineResourceType"; const int32_t TYPE_RESERVE = 1; const int32_t TYPE_OTHERS = 2; +std::unique_ptr RUNTIME_NULL = nullptr; #if defined(NWEB) constexpr int32_t PRELOAD_DELAY_TIME = 2000; //millisecond @@ -1395,6 +1397,59 @@ CJUncaughtExceptionInfo MainThread::CreateCjExceptionInfo(const std::string &bun return uncaughtExceptionInfo; } #endif + +EtsEnv::ETSUncaughtExceptionInfo MainThread::CreateEtsExceptionInfo(const std::string &bundleName, uint32_t versionCode, + const std::string &hapPath, std::string &appRunningId, int32_t pid, std::string &processName) +{ + EtsEnv::ETSUncaughtExceptionInfo uncaughtExceptionInfo; + wptr weak = this; + uncaughtExceptionInfo.uncaughtTask = [weak, bundleName, versionCode, appRunningId = std::move(appRunningId), pid, + processName](std::string summary, const EtsEnv::ETSErrorObject errorObj) { + auto appThread = weak.promote(); + if (appThread == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null appThread"); + return; + } + time_t timet; + time(&timet); + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, "JS_ERROR", + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_KEY_PACKAGE_NAME, bundleName, EVENT_KEY_VERSION, + std::to_string(versionCode), EVENT_KEY_TYPE, JSCRASH_TYPE, EVENT_KEY_HAPPEN_TIME, timet, EVENT_KEY_REASON, + errorObj.name, EVENT_KEY_JSVM, JSVM_TYPE, EVENT_KEY_SUMMARY, summary, EVENT_KEY_PNAME, processName, + EVENT_KEY_APP_RUNING_UNIQUE_ID, appRunningId); + ErrorObject appExecErrorObj = { .name = errorObj.name, .message = errorObj.message, .stack = errorObj.stack }; + FaultData faultData; + faultData.faultType = FaultDataType::JS_ERROR; + faultData.errorObject = appExecErrorObj; + DelayedSingleton::GetInstance()->NotifyAppFault(faultData); + if (ApplicationDataManager::GetInstance().NotifyETSUnhandledException(summary) && + ApplicationDataManager::GetInstance().NotifyETSExceptionObject(appExecErrorObj)) { + return; + } + TAG_LOGE(AAFwkTag::APPKIT, + "\n%{public}s is about to exit due to RuntimeError\nError " + "type:%{public}s\n%{public}s", + bundleName.c_str(), errorObj.name.c_str(), summary.c_str()); + bool foreground = false; + if (appThread->applicationImpl_ && + appThread->applicationImpl_->GetState() == ApplicationImpl::APP_STATE_FOREGROUND) { + foreground = true; + } + int result = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "PROCESS_KILL", + HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PROCESS_NAME", processName, "MSG", KILL_REASON, + "FOREGROUND", foreground); + TAG_LOGW(AAFwkTag::APPKIT, + "hisysevent write result=%{public}d, send event " + "[FRAMEWORK,PROCESS_KILL]," + " pid=%{public}d, processName=%{public}s, msg=%{public}s, " + "foreground=%{public}d", + result, pid, processName.c_str(), KILL_REASON, foreground); + AAFwk::ExitReason exitReason = { REASON_JS_ERROR, errorObj.name }; + AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); + _exit(JS_ERROR_EXIT); + }; + return uncaughtExceptionInfo; +} /** * * @brief Launch the application. @@ -1582,6 +1637,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con } else { #endif AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, isSystemApp); + if (IsNeedEtsInit(appInfo)) { + AbilityRuntime::ETSRuntime::SetAppLibPath(appLibPaths); + } #ifdef CJ_FRONTEND } #endif @@ -1608,7 +1666,14 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con options.pkgContextInfoJsonStringMap = pkgContextInfoJsonStringMap; options.allowArkTsLargeHeap = appInfo.allowArkTsLargeHeap; #ifdef CJ_FRONTEND - options.lang = isCJApp ? AbilityRuntime::Runtime::Language::CJ : AbilityRuntime::Runtime::Language::JS; + if (isCJApp) { + options.langs.emplace(AbilityRuntime::Runtime::Language::CJ, true); + application_->SetCJApplication(true); + } else { + AddRuntimeLang(appInfo, options); + } +#else + AddRuntimeLang(appInfo, options); #endif if (applicationInfo_->appProvisionType == Constants::APP_PROVISION_TYPE_DEBUG) { TAG_LOGD(AAFwkTag::APPKIT, "multi-thread mode: %{public}d", appLaunchData.GetMultiThread()); @@ -1642,12 +1707,12 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con static_cast(hapModuleInfo.aotCompileStatus); } } - auto runtime = AbilityRuntime::Runtime::Create(options); - if (!runtime) { - TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); + std::vector> runtimes = AbilityRuntime::Runtime::CreateRuntimes(options); + if (runtimes.empty()) { + TAG_LOGE(AAFwkTag::APPKIT, "runtimes empty"); return; } - + auto &runtimeVerOne = GetVerOneRuntime(appInfo, runtimes); if (appInfo.debug && appLaunchData.GetDebugApp()) { wptr weak = this; auto cb = [weak]() { @@ -1658,7 +1723,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con } return appThread->NotifyDeviceDisConnect(); }; - runtime->SetDeviceDisconnectCallback(cb); + if (runtimeVerOne != nullptr) { + runtimeVerOne->SetDeviceDisconnectCallback(cb); + } } auto perfCmd = appLaunchData.GetPerfCmd(); @@ -1669,11 +1736,13 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con processName = processInfo_->GetProcessName(); TAG_LOGD(AAFwkTag::APPKIT, "pid is %{public}d, processName is %{public}s", pid, processName.c_str()); } - runtime->SetStopPreloadSoCallback([uid = bundleInfo.applicationInfo.uid, currentPid = pid, - bundleName = appInfo.bundleName]()-> void { - TAG_LOGD(AAFwkTag::APPKIT, "runtime callback and report load abc completed info to rss."); - ResHelper::ReportLoadAbcCompletedInfoToRss(uid, currentPid, bundleName); - }); + if (runtimeVerOne != nullptr) { + runtimeVerOne->SetStopPreloadSoCallback([uid = bundleInfo.applicationInfo.uid, currentPid = pid, + bundleName = appInfo.bundleName]()-> void { + TAG_LOGD(AAFwkTag::APPKIT, "runtime callback and report load abc completed info to rss."); + ResHelper::ReportLoadAbcCompletedInfoToRss(uid, currentPid, bundleName); + }); + } AbilityRuntime::Runtime::DebugOption debugOption; debugOption.isStartWithDebug = appLaunchData.GetDebugApp(); debugOption.processName = processName; @@ -1683,13 +1752,19 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con debugOption.isDebugFromLocal = appLaunchData.GetDebugFromLocal(); debugOption.perfCmd = perfCmd; debugOption.isDeveloperMode = isDeveloperMode_; - runtime->SetDebugOption(debugOption); + if (runtimeVerOne != nullptr) { + runtimeVerOne->SetDebugOption(debugOption); + } if (perfCmd.find(PERFCMD_PROFILE) != std::string::npos || perfCmd.find(PERFCMD_DUMPHEAP) != std::string::npos) { TAG_LOGD(AAFwkTag::APPKIT, "perfCmd is %{public}s", perfCmd.c_str()); - runtime->StartProfiler(debugOption); + if (runtimeVerOne != nullptr) { + runtimeVerOne->StartProfiler(debugOption); + } } else { - runtime->StartDebugMode(debugOption); + if (runtimeVerOne != nullptr) { + runtimeVerOne->StartDebugMode(debugOption); + } } std::vector hqfInfos = appInfo.appQuickFix.deployedAppqfInfo.hqfInfos; @@ -1700,7 +1775,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con it->moduleName.c_str(), it->hqfFilePath.c_str()); modulePaths.insert(std::make_pair(it->moduleName, it->hqfFilePath)); } - runtime->RegisterQuickFixQueryFunc(modulePaths); + if (runtimeVerOne != nullptr) { + runtimeVerOne->RegisterQuickFixQueryFunc(modulePaths); + } } auto bundleName = appInfo.bundleName; @@ -1708,18 +1785,37 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con #ifdef CJ_FRONTEND if (!isCJApp) { #endif - JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo; - uncaughtExceptionInfo.hapPath = hapPath; - UncatchableTaskInfo uncatchableTaskInfo = {bundleName, versionCode, appRunningId, pid, processName}; - InitUncatchableTask(uncaughtExceptionInfo.uncaughtTask, uncatchableTaskInfo); - (static_cast(*runtime)).RegisterUncaughtExceptionHandler(uncaughtExceptionInfo); - JsEnv::UncatchableTask uncatchableTask; - InitUncatchableTask(uncatchableTask, uncatchableTaskInfo, true); - (static_cast(*runtime)).RegisterUncatchableExceptionHandler(uncatchableTask); + for (const auto &runtime : runtimes) { + if (appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0 && + runtime->GetLanguage() == AbilityRuntime::Runtime::Language::JS) { + JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo; + uncaughtExceptionInfo.hapPath = hapPath; + UncatchableTaskInfo uncatchableTaskInfo = {bundleName, versionCode, appRunningId, pid, processName}; + InitUncatchableTask(uncaughtExceptionInfo.uncaughtTask, uncatchableTaskInfo); + (static_cast(*runtime)).RegisterUncaughtExceptionHandler( + uncaughtExceptionInfo); + JsEnv::UncatchableTask uncatchableTask; + InitUncatchableTask(uncatchableTask, uncatchableTaskInfo, true); + (static_cast(*runtime)).RegisterUncatchableExceptionHandler( + uncatchableTask); + } + if ((appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2 || + appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_HYBRID) && + runtime->GetLanguage() == AbilityRuntime::Runtime::Language::ETS) { + auto expectionInfo = + CreateEtsExceptionInfo(bundleName, versionCode, hapPath, appRunningId, pid, processName); + runtime->RegisterUncaughtExceptionHandler((void*)&expectionInfo); + } + } #ifdef CJ_FRONTEND } else { - auto expectionInfo = CreateCjExceptionInfo(bundleName, versionCode, hapPath); - (static_cast(*runtime)).RegisterUncaughtExceptionHandler(expectionInfo); + for (const auto &runtime : runtimes) { + if (appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0 && + runtime->GetLanguage() == AbilityRuntime::Runtime::Language::CJ) { + auto expectionInfo = CreateCjExceptionInfo(bundleName, versionCode, hapPath); + runtime->RegisterUncaughtExceptionHandler((void*)&expectionInfo); + } + } } #endif wptr weak = this; @@ -1733,14 +1829,21 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con }; applicationContext->RegisterProcessSecurityExit(callback); - application_->SetRuntime(std::move(runtime)); - + for (auto &runtime : runtimes) { + application_->AddRuntime(std::move(runtime)); + } std::weak_ptr wpApplication = application_; AbilityLoader::GetInstance().RegisterUIAbility("UIAbility", - [wpApplication]() -> AbilityRuntime::UIAbility* { + [wpApplication](const std::string &language) -> AbilityRuntime::UIAbility* { auto app = wpApplication.lock(); if (app != nullptr) { - return AbilityRuntime::UIAbility::Create(app->GetRuntime()); + if (language == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2) { + return AbilityRuntime::UIAbility::Create(app->GetRuntime( + AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2)); + } else { + return AbilityRuntime::UIAbility::Create(app->GetRuntime( + AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0)); + } } TAG_LOGE(AAFwkTag::APPKIT, "failed"); return nullptr; @@ -1748,33 +1851,18 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con #ifdef CJ_FRONTEND if (!isCJApp) { #endif - auto& jsEngine = (static_cast(*application_->GetRuntime())).GetNativeEngine(); if (application_ != nullptr) { - LoadAllExtensions(jsEngine); + TAG_LOGD(AAFwkTag::APPKIT, "LoadAllExtensions lan:%{public}s", appInfo.codeLanguage.c_str()); + LoadAllExtensions(); } - - IdleTimeCallback callback = [wpApplication](int32_t idleTime) { - auto app = wpApplication.lock(); - if (app == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null app"); - return; - } - auto &runtime = app->GetRuntime(); + if (appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) { + auto &runtime = application_->GetRuntime(appInfo.codeLanguage); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; } - auto& nativeEngine = (static_cast(*runtime)).GetNativeEngine(); - nativeEngine.NotifyIdleTime(idleTime); - }; - idleTime_ = std::make_shared(mainHandler_, callback); - idleTime_->Start(); - - IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc(); - jsEngine.NotifyIdleStatusControl(cb); - - auto helper = std::make_shared(application_); - helper->SetAppFreezeFilterCallback(); + SetJsIdleCallback(wpApplication, runtime); + } #ifdef CJ_FRONTEND } else { LoadAllExtensions(); @@ -1784,7 +1872,8 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con auto usertestInfo = appLaunchData.GetUserTestInfo(); if (usertestInfo) { - if (!PrepareAbilityDelegator(usertestInfo, isStageBased, entryHapModuleInfo, bundleInfo.targetVersion)) { + if (!PrepareAbilityDelegator(usertestInfo, isStageBased, entryHapModuleInfo, bundleInfo.targetVersion, + appInfo.codeLanguage)) { TAG_LOGE(AAFwkTag::APPKIT, "PrepareAbilityDelegator failed"); return; } @@ -1876,7 +1965,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con } #endif if (appLaunchData.IsNeedPreloadModule()) { - PreloadModule(entryHapModuleInfo, application_->GetRuntime()); + for (auto &runtime : application_->GetRuntime()) { + PreloadModule(entryHapModuleInfo, runtime); + } } } @@ -1911,7 +2002,8 @@ void MainThread::InitUncatchableTask(JsEnv::UncatchableTask &uncatchableTask, co EVENT_KEY_PROCESS_RSS_MEMINFO, std::to_string(DumpProcessHelper::GetProcRssMemInfo())); ErrorObject appExecErrorObj = { errorObject.name, errorObject.message, errorObject.stack}; - auto napiEnv = (static_cast(*appThread->application_->GetRuntime())).GetNapiEnv(); + auto napiEnv = (static_cast( + *appThread->application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0))).GetNapiEnv(); AAFwk::ExitReason exitReason = { REASON_JS_ERROR, errorObject.name }; AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); if (!isUncatchable && NapiErrorManager::GetInstance()->NotifyUncaughtException(napiEnv, summary, @@ -2054,7 +2146,7 @@ void MainThread::ProcessMainAbility(const AbilityInfo &info, const std::unique_p } void MainThread::PreloadModule(const AppExecFwk::HapModuleInfo &entryHapModuleInfo, - const std::unique_ptr& runtime) + const std::unique_ptr &runtime) { TAG_LOGI(AAFwkTag::APPKIT, "preload module %{public}s", entryHapModuleInfo.moduleName.c_str()); auto callback = []() {}; @@ -2204,7 +2296,7 @@ void MainThread::HandleUpdatePluginInfoInstalled(const ApplicationInfo &pluginAp TAG_LOGE(AAFwkTag::APPKIT, "null application_"); return; } - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -2254,7 +2346,7 @@ void MainThread::HandleUpdateApplicationInfoInstalled(const ApplicationInfo& app } application_->UpdateApplicationInfoInstalled(appInfo); - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -2342,10 +2434,11 @@ void MainThread::LoadAllExtensions() std::string file = item.extensionLibFile; std::weak_ptr wApp = application_; AbilityLoader::GetInstance().RegisterExtension(item.extensionName, - [wApp, file]() -> AbilityRuntime::Extension* { + [wApp, file](const std::string &language) -> AbilityRuntime::Extension* { auto app = wApp.lock(); if (app != nullptr) { - return AbilityRuntime::ExtensionModuleLoader::GetLoader(file.c_str()).Create(app->GetRuntime()); + return AbilityRuntime::ExtensionModuleLoader::GetLoader(file.c_str()) + .Create(app->GetRuntime(language)); } TAG_LOGE(AAFwkTag::APPKIT, "failed"); return nullptr; @@ -2355,7 +2448,8 @@ void MainThread::LoadAllExtensions() } bool MainThread::PrepareAbilityDelegator(const std::shared_ptr &record, bool isStageBased, - const AppExecFwk::HapModuleInfo &entryHapModuleInfo, uint32_t targetVersion) + const AppExecFwk::HapModuleInfo &entryHapModuleInfo, uint32_t targetVersion, + const std::string &applicationCodeLanguage) { TAG_LOGD(AAFwkTag::APPKIT, "enter, isStageBased = %{public}d", isStageBased); if (!record) { @@ -2365,12 +2459,27 @@ bool MainThread::PrepareAbilityDelegator(const std::shared_ptr & auto args = std::make_shared(record->want); if (isStageBased) { // Stage model TAG_LOGD(AAFwkTag::APPKIT, "Stage model"); - auto testRunner = TestRunner::Create(application_->GetRuntime(), args, false); - auto delegator = IAbilityDelegator::Create(application_->GetRuntime(), application_->GetAppContext(), - std::move(testRunner), record->observer); - AbilityDelegatorRegistry::RegisterInstance(delegator, args); - delegator->SetApiTargetVersion(targetVersion); - delegator->Prepare(); + if (applicationCodeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) { + TAG_LOGI(AAFwkTag::DELEGATOR, "create 1.0 testrunner"); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); + auto testRunner = TestRunner::Create(runtime, args, false); + auto delegator = IAbilityDelegator::Create(runtime, application_->GetAppContext(), + std::move(testRunner), record->observer); + AbilityDelegatorRegistry::RegisterInstance(delegator, args, runtime->GetLanguage()); + delegator->SetApiTargetVersion(targetVersion); + delegator->Prepare(); + } + + if (applicationCodeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2) { + TAG_LOGI(AAFwkTag::DELEGATOR, "create 1.2 testrunner"); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2); + auto testRunner = TestRunner::Create(runtime, args, false); + auto delegator = IAbilityDelegator::Create(runtime, application_->GetAppContext(), + std::move(testRunner), record->observer); + AbilityDelegatorRegistry::RegisterInstance(delegator, args, runtime->GetLanguage()); + delegator->SetApiTargetVersion(targetVersion); + delegator->Prepare(); + } } else { // FA model TAG_LOGD(AAFwkTag::APPKIT, "FA model"); AbilityRuntime::Runtime::Options options; @@ -2400,7 +2509,7 @@ bool MainThread::PrepareAbilityDelegator(const std::shared_ptr & } auto delegator = std::make_shared( application_->GetAppContext(), std::move(testRunner), record->observer); - AbilityDelegatorRegistry::RegisterInstance(delegator, args); + AbilityDelegatorRegistry::RegisterInstance(delegator, args, AbilityRuntime::Runtime::Language::JS); delegator->SetApiTargetVersion(targetVersion); delegator->Prepare(); } @@ -2461,7 +2570,7 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & TAG_LOGE(AAFwkTag::APPKIT, "null application"); return; } - auto& runtime = application->GetRuntime(); + auto &runtime = application->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); appThread->UpdateRuntimeModuleChecker(runtime); #ifdef APP_ABILITY_USE_TWO_RUNNER AbilityThread::AbilityThreadMain(application, abilityRecord, stageContext); @@ -2488,7 +2597,7 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & return; } SetProcessExtensionType(abilityRecord); - auto& runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); UpdateRuntimeModuleChecker(runtime); #ifdef APP_ABILITY_USE_TWO_RUNNER AbilityThread::AbilityThreadMain(application_, abilityRecord, stageContext); @@ -2851,7 +2960,7 @@ void MainThread::HandleDumpHeapPrepare() TAG_LOGE(AAFwkTag::APPKIT, "null app"); return; } - auto &runtime = app->GetRuntime(); + auto &runtime = app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -2871,7 +2980,7 @@ void MainThread::HandleDumpHeap(bool isPrivate) TAG_LOGE(AAFwkTag::APPKIT, "null app"); return; } - auto &runtime = app->GetRuntime(); + auto &runtime = app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -2924,11 +3033,11 @@ void MainThread::DestroyHeapProfiler() auto task = [] { auto app = applicationForDump_.lock(); - if (app == nullptr || app->GetRuntime() == nullptr) { + if (app == nullptr || app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; } - app->GetRuntime()->DestroyHeapProfiler(); + app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0)->DestroyHeapProfiler(); }; mainHandler_->PostTask(task, "MainThread:DestroyHeapProfiler"); } @@ -2943,11 +3052,11 @@ void MainThread::ForceFullGC() auto task = [] { auto app = applicationForDump_.lock(); - if (app == nullptr || app->GetRuntime() == nullptr) { + if (app == nullptr || app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; } - app->GetRuntime()->ForceFullGC(); + app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0)->ForceFullGC(); }; mainHandler_->PostTask(task, "MainThread:ForceFullGC"); } @@ -3675,7 +3784,7 @@ int32_t MainThread::ChangeAppGcState(int32_t state, uint64_t tid) TAG_LOGE(AAFwkTag::APPKIT, "null application_"); return ERR_INVALID_VALUE; } - auto &runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return ERR_INVALID_VALUE; @@ -3727,7 +3836,7 @@ int32_t MainThread::OnAttachLocalDebug(bool isDebugFromLocal) TAG_LOGE(AAFwkTag::APPKIT, "null application_"); return ERR_INVALID_VALUE; } - auto &runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return ERR_INVALID_VALUE; @@ -3949,7 +4058,7 @@ void MainThread::HandleCacheProcess() // force gc if (application_ != nullptr) { - auto &runtime = application_->GetRuntime(); + auto &runtime = application_->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; @@ -3958,6 +4067,38 @@ void MainThread::HandleCacheProcess() } } +void MainThread::AddRuntimeLang(ApplicationInfo &appInfo, AbilityRuntime::Runtime::Options &options) +{ + if (appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2) { + options.langs.emplace(AbilityRuntime::Runtime::Language::ETS, true); + } else if (appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_HYBRID) { + options.langs.emplace(AbilityRuntime::Runtime::Language::ETS, true); + } else { + options.langs.emplace(AbilityRuntime::Runtime::Language::JS, true); + } +} + +bool MainThread::IsNeedEtsInit(const ApplicationInfo &appInfo) +{ + return appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2 || + appInfo.codeLanguage == AbilityRuntime::CODE_LANGUAGE_ARKTS_HYBRID; +} + +const std::unique_ptr &MainThread::GetVerOneRuntime( + const ApplicationInfo &appInfo, const std::vector> &runtimes) +{ + if (appInfo.codeLanguage != AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) { + return RUNTIME_NULL; + } + for (auto &runtime : runtimes) { + if (runtime->GetLanguage() == AbilityRuntime::Runtime::Language::JS || + runtime->GetLanguage() == AbilityRuntime::Runtime::Language::CJ) { + return runtime; + } + } + return RUNTIME_NULL; +} + void MainThread::HandleConfigByPlugin(Configuration &config, BundleInfo &bundleInfo) { if (PC_LIBRARY_PATH == nullptr) { @@ -3980,5 +4121,33 @@ void MainThread::HandleConfigByPlugin(Configuration &config, BundleInfo &bundleI entry(config, bundleInfo); } + +void MainThread::SetJsIdleCallback(const std::weak_ptr &wpApplication, + const std::unique_ptr &runtime) +{ + auto &jsEngine = (static_cast(*runtime)).GetNativeEngine(); + IdleTimeCallback callback = [wpApplication](int32_t idleTime) { + auto app = wpApplication.lock(); + if (app == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null app"); + return; + } + auto &runtime = app->GetRuntime(AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); + if (runtime == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); + return; + } + auto &nativeEngine = (static_cast(*runtime)).GetNativeEngine(); + nativeEngine.NotifyIdleTime(idleTime); + }; + idleTime_ = std::make_shared(mainHandler_, callback); + idleTime_->Start(); + + IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc(); + jsEngine.NotifyIdleStatusControl(cb); + + auto helper = std::make_shared(application_); + helper->SetAppFreezeFilterCallback(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 45831ff8001811c05b876e26fa10344ea10802b4..41713dde52b85c112228af397a2d7c92e0cf22f6 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -37,6 +37,7 @@ #include "iservice_registry.h" #include "runtime.h" #include "js_runtime.h" +#include "ets_runtime.h" #include "startup_manager.h" #include "system_ability_definition.h" #include "syspara/parameter.h" @@ -51,6 +52,7 @@ namespace OHOS { namespace AppExecFwk { namespace { constexpr const char* PERSIST_DARKMODE_KEY = "persist.ace.darkmode"; + std::unique_ptr RUNTIME_NULL = nullptr; } REGISTER_APPLICATION(OHOSApplication, OHOSApplication) constexpr int32_t APP_ENVIRONMENT_OVERWRITE = 1; @@ -77,11 +79,14 @@ void OHOSApplication::OnForeground() abilityRuntimeContext_->NotifyApplicationForeground(); } - if (runtime_ == nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "NotifyApplicationState, runtime_ is nullptr"); - return; + for (const auto &runtime : runtimes_) { + if (runtime == nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "NotifyApplicationState, runtime is nullptr"); + continue; + } + runtime->NotifyApplicationState(false); } - runtime_->NotifyApplicationState(false); + TAG_LOGD(AAFwkTag::APPKIT, "NotifyApplicationState::OnForeground end"); } @@ -97,11 +102,13 @@ void OHOSApplication::OnBackground() abilityRuntimeContext_->NotifyApplicationBackground(); } - if (runtime_ == nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "runtime_ is nullptr"); - return; + for (const auto &runtime : runtimes_) { + if (runtime == nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "runtime is nullptr"); + continue; + } + runtime->NotifyApplicationState(true); } - runtime_->NotifyApplicationState(true); } void OHOSApplication::DumpApplication() @@ -149,18 +156,18 @@ void OHOSApplication::DumpApplication() } /** - * @brief Set Runtime + * @brief Add Runtime * * @param runtime Runtime instance. */ -void OHOSApplication::SetRuntime(std::unique_ptr&& runtime) +void OHOSApplication::AddRuntime(std::unique_ptr &&runtime) { TAG_LOGD(AAFwkTag::APPKIT, "begin"); if (runtime == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null runtime"); return; } - runtime_ = std::move(runtime); + runtimes_.emplace_back(std::move(runtime)); } /** @@ -369,6 +376,25 @@ void OHOSApplication::SetAppEnv(const std::vector& appEnvironmen return; } +void OHOSApplication::PreloadHybridModule(const HapModuleInfo &hapModuleInfo) const +{ + if (hapModuleInfo.codeLanguage != Constants::CODE_LANGUAGE_HYBRID) { + TAG_LOGD(AAFwkTag::APPKIT, "not hybrid runtime"); + return; + } + for (const auto &runtime : runtimes_) { + bool isEsmode = hapModuleInfo.compileMode == CompileMode::ES_MODULE; + bool useCommonTrunk = false; + for (const auto& md : hapModuleInfo.metadata) { + if (md.name == "USE_COMMON_CHUNK") { + useCommonTrunk = md.value == "true"; + break; + } + } + runtime->PreloadModule(hapModuleInfo.moduleName, hapModuleInfo.hapPath, isEsmode, useCommonTrunk); + } +} + std::shared_ptr OHOSApplication::AddAbilityStage( const std::shared_ptr &abilityRecord, const std::function &)> &callback, bool &isAsyncCallback) @@ -413,8 +439,10 @@ std::shared_ptr OHOSApplication::AddAbilityStage( TAG_LOGE(AAFwkTag::APPKIT, "null hapModuleInfo"); return nullptr; } - if (runtime_ && (runtime_->GetLanguage() == AbilityRuntime::Runtime::Language::JS)) { - static_cast(*runtime_).SetPkgContextInfoJson( + PreloadHybridModule(*hapModuleInfo); + auto &runtime = GetRuntime(abilityInfo->codeLanguage); + if (runtime && (runtime->GetLanguage() == AbilityRuntime::Runtime::Language::JS)) { + static_cast(*runtime).SetPkgContextInfoJson( hapModuleInfo->moduleName, hapModuleInfo->hapPath, hapModuleInfo->packageName); } SetAppEnv(hapModuleInfo->appEnvironments); @@ -425,7 +453,8 @@ std::shared_ptr OHOSApplication::AddAbilityStage( stageContext->SetResourceManager(rm); } - abilityStage = AbilityRuntime::AbilityStage::Create(runtime_, *hapModuleInfo); + auto &runtimeStage = GetRuntime(hapModuleInfo->codeLanguage); + abilityStage = AbilityRuntime::AbilityStage::Create(runtimeStage, *hapModuleInfo); if (abilityStage == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null abilityStage"); return nullptr; @@ -608,8 +637,8 @@ bool OHOSApplication::AddAbilityStage( return false; } - if (runtime_ == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null runtime_"); + if (runtimes_.empty()) { + TAG_LOGE(AAFwkTag::APPKIT, "runtimes empty"); return false; } @@ -633,7 +662,8 @@ bool OHOSApplication::AddAbilityStage( stageContext->SetResourceManager(rm); } - auto abilityStage = AbilityRuntime::AbilityStage::Create(runtime_, *moduleInfo); + auto &runtime = GetRuntime(moduleInfo->codeLanguage); + auto abilityStage = AbilityRuntime::AbilityStage::Create(runtime, *moduleInfo); if (abilityStage == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null abilityStage"); return false; @@ -688,9 +718,9 @@ std::shared_ptr OHOSApplication::GetAppContext() const return abilityRuntimeContext_; } -const std::unique_ptr& OHOSApplication::GetRuntime() const +const std::vector> &OHOSApplication::GetRuntime() const { - return runtime_; + return runtimes_; } void OHOSApplication::SetConfiguration(const Configuration &config) @@ -815,32 +845,60 @@ void OHOSApplication::SetExtensionTypeMap(std::map map) bool OHOSApplication::NotifyLoadRepairPatch(const std::string &hqfFile, const std::string &hapPath) { - if (runtime_ == nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + if (runtimes_.empty()) { + TAG_LOGD(AAFwkTag::APPKIT, "runtimes empty"); return true; } - return runtime_->LoadRepairPatch(hqfFile, hapPath); + for (const auto &runtime : runtimes_) { + if (runtime == nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + continue; + } + if (!runtime->LoadRepairPatch(hqfFile, hapPath)) { + return false; + } + } + return true; } bool OHOSApplication::NotifyHotReloadPage() { - if (runtime_ == nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + if (runtimes_.empty()) { + TAG_LOGD(AAFwkTag::APPKIT, "runtimes empty"); return true; } - return runtime_->NotifyHotReloadPage(); + for (const auto &runtime : runtimes_) { + if (runtime == nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + continue; + } + if (!runtime->NotifyHotReloadPage()) { + return false; + } + } + return true; } bool OHOSApplication::NotifyUnLoadRepairPatch(const std::string &hqfFile) { - if (runtime_ == nullptr) { - TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + if (runtimes_.empty()) { + TAG_LOGD(AAFwkTag::APPKIT, "runtimes empty"); return true; } - return runtime_->UnLoadRepairPatch(hqfFile); + for (const auto &runtime : runtimes_) { + if (runtime == nullptr) { + TAG_LOGD(AAFwkTag::APPKIT, "null runtime"); + continue; + } + if (!runtime->UnLoadRepairPatch(hqfFile)) { + return false; + } + } + + return true; } void OHOSApplication::CleanAppTempData(bool isLastProcess) @@ -1080,5 +1138,35 @@ bool OHOSApplication::GetDisplayConfig(uint64_t displayId, float &density, std:: return true; } #endif + +const std::unique_ptr &OHOSApplication::GetRuntime(const std::string &language) const +{ + for (auto &runtime : runtimes_) { + if (runtime->GetLanguage() == ConvertLangToCode(language)) { + return runtime; + } + } + return RUNTIME_NULL; +} + +void OHOSApplication::SetCJApplication(bool isCJApplication) +{ + isCJApplication_ = isCJApplication; +} + +AbilityRuntime::Runtime::Language OHOSApplication::ConvertLangToCode(const std::string &language) const +{ + if (language == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) { + if (isCJApplication_) { + return AbilityRuntime::Runtime::Language::CJ; + } else { + return AbilityRuntime::Runtime::Language::JS; + } + } else if (language == AbilityRuntime::CODE_LANGUAGE_ARKTS_1_2) { + return AbilityRuntime::Runtime::Language::ETS; + } else { + return AbilityRuntime::Runtime::Language::UNKNOWN; + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index ecf1697834d004eebefd5e2e51dbd930083283d0..5ac8d635e22ddc1bb1fa8bc735bfe17371fec614 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -118,16 +118,6 @@ bool CJRuntime::Initialize(const Options& options) return true; } -void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) -{ - auto cjEnv = OHOS::CJEnv::LoadInstance(); - if (cjEnv == nullptr) { - TAG_LOGE(AAFwkTag::CJRUNTIME, "null cjEnv"); - return; - } - cjEnv->registerCJUncaughtExceptionHandler(uncaughtExceptionInfo); -} - bool CJRuntime::IsCJAbility(const std::string& info) { // in cj application, the srcEntry format should be packageName.AbilityClassName. @@ -368,4 +358,14 @@ void CJRuntime::ForceFullGC(uint32_t tid) return; } cjEnv->forceFullGC(); +} + +void CJRuntime::RegisterUncaughtExceptionHandler(void* uncaughtExceptionInfo) +{ + auto cjEnv = OHOS::CJEnv::LoadInstance(); + if (cjEnv == nullptr) { + TAG_LOGE(AAFwkTag::CJRUNTIME, "null cjEnv"); + return; + } + cjEnv->registerCJUncaughtExceptionHandler(*static_cast(uncaughtExceptionInfo)); } \ No newline at end of file diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 4b04f031c12904c7d98a7d13b749f99b2dd9f16b..cb7c9a217e7b2f69311463c804193995c8ffdecf 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -1765,5 +1765,12 @@ void JsRuntime::StartLocalDebugMode(bool isDebugFromLocal) debugOption_.isDebugFromLocal = isDebugFromLocal; StartDebugMode(debugOption_); } + +void JsRuntime::RegisterUncaughtExceptionHandler(void *uncaughtExceptionInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + CHECK_POINTER(jsEnv_); + jsEnv_->RegisterUncaughtExceptionHandler(*static_cast(uncaughtExceptionInfo)); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/runtime/runtime.cpp b/frameworks/native/runtime/runtime.cpp index 26362dd0dbbe6724c623e7a42581ceee0bdb3892..0beb1b4395345e2673aecb38702be5b990642801 100644 --- a/frameworks/native/runtime/runtime.cpp +++ b/frameworks/native/runtime/runtime.cpp @@ -19,6 +19,7 @@ #include "cj_runtime.h" #endif #include "js_runtime.h" +#include "ets_runtime.h" namespace OHOS { namespace AbilityRuntime { @@ -26,8 +27,45 @@ namespace { std::unique_ptr g_preloadedInstance; } -std::unique_ptr Runtime::Create(const Runtime::Options& options) +std::vector> Runtime::CreateRuntimes(Runtime::Options &options) { + std::vector> runtimes; + for (auto lang : options.langs) { + switch (lang.first) { + case Runtime::Language::JS: + options.lang = Runtime::Language::JS; + runtimes.emplace_back(JsRuntime::Create(options)); + break; +#ifdef CJ_FRONTEND + case Runtime::Language::CJ: + options.lang = Runtime::Language::CJ; + runtimes.emplace_back(CJRuntime::Create(options)); + break; +#endif + case Runtime::Language::ETS: { + options.lang = Runtime::Language::JS; + auto &jsRuntime = runtimes.emplace_back(JsRuntime::Create(options)); + options.lang = Runtime::Language::ETS; + runtimes.emplace_back(ETSRuntime::Create(options, + static_cast(jsRuntime.get()))); + break; + } + default: + runtimes.emplace_back(std::unique_ptr()); + break; + } + } + return runtimes; +} + +std::unique_ptr Runtime::Create(Runtime::Options &options) +{ + std::unique_ptr jsRuntime; + if (options.lang == Runtime::Language::ETS) { + options.lang = Runtime::Language::JS; + jsRuntime = JsRuntime::Create(options); + options.lang = Runtime::Language::ETS; + } switch (options.lang) { case Runtime::Language::JS: return JsRuntime::Create(options); @@ -35,6 +73,8 @@ std::unique_ptr Runtime::Create(const Runtime::Options& options) case Runtime::Language::CJ: return CJRuntime::Create(options); #endif + case Runtime::Language::ETS: + return ETSRuntime::Create(options, jsRuntime.get()); default: return std::unique_ptr(); } diff --git a/frameworks/simulator/ability_simulator/src/js_runtime.cpp b/frameworks/simulator/ability_simulator/src/js_runtime.cpp index 7e173d8a07c02d6a7e8b4b074b6642a97dd33f1b..3bed249733a419884556d1f715175eaeb43bb774 100644 --- a/frameworks/simulator/ability_simulator/src/js_runtime.cpp +++ b/frameworks/simulator/ability_simulator/src/js_runtime.cpp @@ -158,5 +158,8 @@ std::unique_ptr JsRuntime::LoadSystemModuleByEngine( napi_create_reference(env, instanceValue, 1, &result); return std::unique_ptr(reinterpret_cast(result)); } + +void JsRuntime::RegisterUncaughtExceptionHandler(void *uncaughtExceptionInfo) +{} } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/runtime/BUILD.gn b/interfaces/inner_api/runtime/BUILD.gn index ace9ee9c4fa064a4378198a4aa06e711275dd0ce..6dd88718d98e8ce8867b0a960fb1bd571d288f8c 100644 --- a/interfaces/inner_api/runtime/BUILD.gn +++ b/interfaces/inner_api/runtime/BUILD.gn @@ -52,6 +52,7 @@ ohos_shared_library("runtime") { branch_protector_ret = "pac_ret" include_dirs = [ + "${ability_runtime_path}/ets_environment/interfaces/inner_api", "${ability_runtime_path}/services/abilitymgr/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_path}/frameworks/ets/ani/enum_convert", @@ -91,6 +92,7 @@ ohos_shared_library("runtime") { "${ability_runtime_innerkits_path}/connect_server_manager:connect_server_manager", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/ets_environment/frameworks/ets_environment:ets_environment", "${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:record_cost_time_util", diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index 0d406dc6f33831c5cb9d87bdf67ff7716a125292..04778b740086e49638f4e4ad07afd4a2051d6168 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -55,6 +55,8 @@ public: const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) override {} void PreloadModule(const std::string& moduleName, const std::string& srcPath, const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override {} + void PreloadModule(const std::string& moduleName, const std::string& hapPath, + bool isEsMode, bool useCommonTrunk) override {} void FinishPreload() override {} bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; } bool NotifyHotReloadPage() override { return false; } @@ -72,8 +74,8 @@ public: void DumpCpuProfile() override {}; void AllowCrossThreadExecution() override {}; void GetHeapPrepare() override {}; - void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo); static bool RegisterCangjieCallback(); + void RegisterUncaughtExceptionHandler(void* uncaughtExceptionInfo) override; private: bool StartDebugger(); diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index d573886e3c6ebcf7164668e9129cedb044bedfed..dcc410a2cf06f39e99a6cb99bf728dbb3a9483a3 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -103,6 +103,8 @@ public: const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) override; void PreloadModule(const std::string& moduleName, const std::string& srcPath, const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override; + void PreloadModule(const std::string &moduleName, const std::string &hapPath, + bool isEsMode, bool useCommonTrunk) override {} bool PopPreloadObj(const std::string& key, std::unique_ptr& obj); void StartDebugMode(const DebugOption debugOption) override; void SetDebugOption(const DebugOption debugOption) override; @@ -156,6 +158,7 @@ public: void SetPkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName); void UpdatePkgContextInfoJson(const std::string& moduleName, const std::string& hapPath, const std::string& packageName); + void RegisterUncaughtExceptionHandler(void *uncaughtExceptionInfo) override; private: void FinishPreload() override; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 5b3312752f12c526bc9eac08395af8e769c84cc4..faf6685bbd2e6e2d5159820a1b539585682e7f1b 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -27,14 +27,23 @@ namespace AppExecFwk { class EventRunner; } // namespace AppExecFwk namespace AbilityRuntime { +namespace { +const std::string CODE_LANGUAGE_ARKTS_1_0 = "1.1"; +const std::string CODE_LANGUAGE_ARKTS_1_2 = "1.2"; +const std::string CODE_LANGUAGE_ARKTS_HYBRID = "hybrid"; +} // namespace + class Runtime { public: enum class Language { JS = 0, - CJ + CJ, + ETS, + UNKNOWN, }; struct Options { + std::map langs; Language lang = Language::JS; std::string bundleName; std::string moduleName; @@ -80,7 +89,8 @@ public: bool isDeveloperMode; }; - static std::unique_ptr Create(const Options& options); + static std::vector> CreateRuntimes(Options &options); + static std::unique_ptr Create(Options &options); static void SavePreloaded(std::unique_ptr&& instance); static std::unique_ptr GetPreloaded(); @@ -108,6 +118,8 @@ public: const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) = 0; virtual void PreloadModule(const std::string& moduleName, const std::string& srcPath, const std::string& hapPath, bool isEsMode, bool useCommonTrunk) = 0; + virtual void PreloadModule(const std::string &moduleName, const std::string &hapPath, + bool isEsMode, bool useCommonTrunk) {} virtual void FinishPreload() = 0; virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; virtual bool NotifyHotReloadPage() = 0; @@ -122,6 +134,7 @@ public: Runtime(Runtime&&) = delete; Runtime& operator=(const Runtime&) = delete; Runtime& operator=(Runtime&&) = delete; + virtual void RegisterUncaughtExceptionHandler(void *uncaughtExceptionInfo) {} }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/ability_runtime/ets_extension_context.h b/interfaces/kits/native/ability/ability_runtime/ets_extension_context.h new file mode 100644 index 0000000000000000000000000000000000000000..12c99e56649b81514866e0d1a59a8d4f1fe8e590 --- /dev/null +++ b/interfaces/kits/native/ability/ability_runtime/ets_extension_context.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H + +#include "extension_context.h" +#include "ani.h" + +namespace OHOS { +namespace AbilityRuntime { +void CreatEtsExtensionContext(ani_env* aniEnv, ani_class contextClass, ani_object contextObj, + std::shared_ptr context, + std::shared_ptr abilityInfo); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_STS_EXTENSION_CONTEXT_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/ability_loader.h b/interfaces/kits/native/ability/native/ability_loader.h index 23947ec898c2169a47b0bfab43365a590337d66b..18fd34818d50bb9987e01b62b66220331fc1f784 100644 --- a/interfaces/kits/native/ability/native/ability_loader.h +++ b/interfaces/kits/native/ability/native/ability_loader.h @@ -28,9 +28,9 @@ namespace OHOS { namespace AppExecFwk { -using CreateExtension = std::function; +using CreateExtension = std::function; using CreateAblity = std::function; -using CreateUIAbility = std::function; +using CreateUIAbility = std::function; #ifdef ABILITY_WINDOW_SUPPORT using CreateSlice = std::function; #endif @@ -90,14 +90,15 @@ public: * * @return return Ability address */ - AbilityRuntime::Extension *GetExtensionByName(const std::string &abilityName); + AbilityRuntime::Extension *GetExtensionByName(const std::string &abilityName, + const std::string &language = AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); /** * @brief Get UIAbility address * @param abilityName UIAbility classname * @return return UIAbility address */ - AbilityRuntime::UIAbility *GetUIAbilityByName(const std::string &abilityName); + AbilityRuntime::UIAbility *GetUIAbilityByName(const std::string &abilityName, const std::string &language); #ifdef ABILITY_WINDOW_SUPPORT void RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc); diff --git a/interfaces/kits/native/appkit/ability_delegator/ability_delegator_registry.h b/interfaces/kits/native/appkit/ability_delegator/ability_delegator_registry.h index 1fd257b82310397e327403373df4e0ca6800e3ff..57f9c383be7d8d3bf41457d9cfe902ea43a2a0f5 100644 --- a/interfaces/kits/native/appkit/ability_delegator/ability_delegator_registry.h +++ b/interfaces/kits/native/appkit/ability_delegator/ability_delegator_registry.h @@ -24,6 +24,7 @@ #include "cj_ability_delegator_impl.h" #endif #include "iability_delegator.h" +#include "runtime.h" namespace OHOS { namespace AppExecFwk { @@ -34,7 +35,8 @@ public: * * @return the AbilityDelegator object initialized when the application is started. */ - static std::shared_ptr GetAbilityDelegator(); + static std::shared_ptr GetAbilityDelegator( + const AbilityRuntime::Runtime::Language &language = AbilityRuntime::Runtime::Language::JS); #ifdef CJ_FRONTEND /** @@ -60,10 +62,11 @@ public: * @param args, Indicates the AbilityDelegatorArgs object. */ static void RegisterInstance( - const std::shared_ptr& delegator, const std::shared_ptr& args); + const std::shared_ptr &delegator, const std::shared_ptr &args, + const AbilityRuntime::Runtime::Language &language); private: - static std::shared_ptr abilityDelegator_; + static std::map> abilityDelegator_; static std::shared_ptr abilityDelegatorArgs_; }; } // namespace AppExecFwk diff --git a/interfaces/kits/native/appkit/app/application_data_manager.h b/interfaces/kits/native/appkit/app/application_data_manager.h index 3f8bb01b4e78f8521570be79cb8903df71347d6f..08ddb478a740ecafb472a6d10f3cc96fda3c749b 100644 --- a/interfaces/kits/native/appkit/app/application_data_manager.h +++ b/interfaces/kits/native/appkit/app/application_data_manager.h @@ -29,9 +29,11 @@ public: void AddErrorObserver(const std::shared_ptr &observer); bool NotifyUnhandledException(const std::string &errMsg); bool NotifyCJUnhandledException(const std::string &errMsg); + bool NotifyETSUnhandledException(const std::string &errMsg); void RemoveErrorObserver(); bool NotifyExceptionObject(const AppExecFwk::ErrorObject &errorObj); bool NotifyCJExceptionObject(const AppExecFwk::ErrorObject &errorObj); + bool NotifyETSExceptionObject(const AppExecFwk::ErrorObject &errorObj); private: ApplicationDataManager(); diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index cd5a86a89c5cbfb55f5c95dc2c01fbc909339670..a7e7e7f94156d3490723c2b04222bc51170ae840 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -40,6 +40,7 @@ #include "resource_manager.h" #include "runtime.h" #include "watchdog.h" +#include "ets_runtime.h" #ifdef CJ_FRONTEND #include "cj_envsetup.h" @@ -323,6 +324,8 @@ public: CJUncaughtExceptionInfo CreateCjExceptionInfo(const std::string &bundleName, uint32_t versionCode, const std::string &hapPath); #endif + EtsEnv::ETSUncaughtExceptionInfo CreateEtsExceptionInfo(const std::string &bundleName, uint32_t versionCode, + const std::string &hapPath, std::string &appRunningId, int32_t pid, std::string &processName); /** * @brief Notify NativeEngine GC of status change. * @@ -622,7 +625,8 @@ private: * */ bool PrepareAbilityDelegator(const std::shared_ptr &record, bool isStageBased, - const AppExecFwk::HapModuleInfo &entryHapModuleInfo, uint32_t targetVersion); + const AppExecFwk::HapModuleInfo &entryHapModuleInfo, uint32_t targetVersion, + const std::string &applicationCodeLanguage); /** * @brief Set current process extension type @@ -797,6 +801,12 @@ private: void SetAppDebug(uint32_t modeFlag, bool isDebug); void GetPluginNativeLibPath(std::vector &pluginBundleInfos, AppLibPathMap &appLibPaths); + void AddRuntimeLang(ApplicationInfo &appInfo, AbilityRuntime::Runtime::Options &options); + bool IsNeedEtsInit(const ApplicationInfo &appInfo); + const std::unique_ptr &GetVerOneRuntime( + const ApplicationInfo &appInfo, const std::vector> &runtimes); + void SetJsIdleCallback(const std::weak_ptr &wpApplication, + const std::unique_ptr &runtime); std::vector fileEntries_; std::vector nativeFileEntries_; diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 783bd601495d60835ba55080a9bf51a95ec5992d..3bc1c5697a8c5f78a57f34fd5c3b3fb2850cd708 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -27,6 +27,7 @@ #include "ability_stage_context.h" #include "application_configuration_manager.h" #include "app_launch_data.h" +#include "runtime.h" namespace OHOS { namespace AbilityRuntime { @@ -49,11 +50,11 @@ public: void DumpApplication(); /** - * @brief Set Runtime + * @brief Add Runtime * * @param runtime Runtime instance. */ - void SetRuntime(std::unique_ptr&& runtime); + void AddRuntime(std::unique_ptr &&runtime); /** * @brief Set ApplicationContext @@ -168,12 +169,19 @@ public: */ std::shared_ptr GetAppContext() const; + /** + * @brief return the application runtimes + * + * @param runtime + */ + const std::vector> &GetRuntime() const; + /** * @brief return the application runtime * * @param runtime */ - const std::unique_ptr& GetRuntime() const; + const std::unique_ptr &GetRuntime(const std::string &language) const; /* * @@ -236,6 +244,8 @@ public: void PreloadAppStartup(const BundleInfo &bundleInfo, const std::string &preloadModuleName, std::shared_ptr startupTaskData); + void SetCJApplication(bool isCJApplication = false); + private: void UpdateAppContextResMgr(const Configuration &config); bool IsUpdateColorNeeded(Configuration &config, AbilityRuntime::SetLevel level); @@ -251,14 +261,17 @@ private: const AppExecFwk::HapModuleInfo &hapModuleInfo, const std::function& callback); bool IsMainProcess(const std::string &bundleName, const std::string &process); + AbilityRuntime::Runtime::Language ConvertLangToCode(const std::string &language) const; + void PreloadHybridModule(const HapModuleInfo &hapModuleInfo) const; private: std::shared_ptr abilityRecordMgr_ = nullptr; std::shared_ptr abilityRuntimeContext_ = nullptr; std::unordered_map> abilityStages_; - std::unique_ptr runtime_; + std::vector> runtimes_; std::shared_ptr configuration_ = nullptr; std::map extensionTypeMap_; + bool isCJApplication_ = false; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/moduletest/ability_delegator_test/ability_delegator_module_test.cpp b/test/moduletest/ability_delegator_test/ability_delegator_module_test.cpp index 5e3cda2168650c619e2502d1df56c24a0ab441c0..186fa67b1e63dae7277a03e8231f5715f02faf09 100644 --- a/test/moduletest/ability_delegator_test/ability_delegator_module_test.cpp +++ b/test/moduletest/ability_delegator_test/ability_delegator_module_test.cpp @@ -165,7 +165,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0100, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -204,7 +205,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0200, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -239,7 +241,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0300, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -277,7 +280,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0400, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -310,7 +314,8 @@ HWTEST_F(AbilityDelegatorModuleTest2, Ability_Delegator_Args_Test_0500, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2()); @@ -342,7 +347,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0600, Function std::shared_ptr context = std::make_shared(); EXPECT_TRUE(context != nullptr); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -377,7 +383,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0700, Function std::shared_ptr context = std::make_shared(); EXPECT_TRUE(context != nullptr); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -411,7 +418,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0800, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -443,7 +451,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_0900, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -476,7 +485,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1000, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -514,7 +524,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1100, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -551,7 +562,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1200, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -590,7 +602,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1300, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -629,7 +642,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1400, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -662,7 +676,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1500, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -701,7 +716,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1600, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -734,7 +750,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1700, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -773,7 +790,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1800, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -806,7 +824,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_1900, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -845,7 +864,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2000, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -884,7 +904,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2100, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -923,7 +944,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2200, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -962,7 +984,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2300, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1004,13 +1027,15 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2400, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); abilityDelegator->abilityMonitors_.clear(); std::shared_ptr mockMonitor = std::make_shared(ABILITY_NAME); @@ -1049,13 +1074,15 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2500, Function std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); abilityDelegator->abilityMonitors_.clear(); std::shared_ptr mockMonitor = std::make_shared(ABILITY_NAME); @@ -1091,7 +1118,8 @@ HWTEST_F(AbilityDelegatorModuleTest, Ability_Delegator_Args_Test_2600, Function } std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); diff --git a/test/moduletest/ability_delegator_test/ability_delegator_registry_module_test.cpp b/test/moduletest/ability_delegator_test/ability_delegator_registry_module_test.cpp index 526f8acd5fcadae1e1ab27533041c021ced70db8..d5e7c265d330b6125d8cc4ff25b0b31b77c1d6d1 100644 --- a/test/moduletest/ability_delegator_test/ability_delegator_registry_module_test.cpp +++ b/test/moduletest/ability_delegator_test/ability_delegator_registry_module_test.cpp @@ -81,13 +81,16 @@ HWTEST_F(AbilityDelegatorRegistryModuleTest, } std::shared_ptr abilityArgs = std::make_shared(want); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); std::shared_ptr abilityDelegator = std::make_shared(nullptr, std::move(testRunner), nullptr); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); - EXPECT_EQ(AbilityDelegatorRegistry::GetAbilityDelegator(), abilityDelegator); + EXPECT_EQ(AbilityDelegatorRegistry::GetAbilityDelegator(OHOS::AbilityRuntime::Runtime::Language::JS), + abilityDelegator); EXPECT_EQ(AbilityDelegatorRegistry::GetArguments(), abilityArgs); } diff --git a/test/moduletest/ability_delegator_test/js_test_runner_module_test.cpp b/test/moduletest/ability_delegator_test/js_test_runner_module_test.cpp index 52625ddd158a1ee5defe34ce52b864315d5aaf21..81ab9b9e87332c49a1923e7229ff38a79cdde9d5 100644 --- a/test/moduletest/ability_delegator_test/js_test_runner_module_test.cpp +++ b/test/moduletest/ability_delegator_test/js_test_runner_module_test.cpp @@ -118,13 +118,15 @@ HWTEST_F(JsTestRunnerModuleTest, Js_Test_Runner_Module_Test_0100, Function | Med std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); JsTestRunner* jsRunnerdrive = nullptr; jsRunnerdrive->ReportFinished(REPORT_FINISH_MSG); @@ -157,13 +159,15 @@ HWTEST_F(JsTestRunnerModuleTest, Js_Test_Runner_Module_Test_0200, Function | Med std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); sptr shobserver = sptr(new MockTestObserverStub); abilityDelegator->observer_ = shobserver; diff --git a/test/unittest/ability_service_extension_test/BUILD.gn b/test/unittest/ability_service_extension_test/BUILD.gn index 18412fa0cfbbd13cf9f38392f04e57a8976d90ee..398c5223ede030d69a84685a49697ce21c5b373f 100644 --- a/test/unittest/ability_service_extension_test/BUILD.gn +++ b/test/unittest/ability_service_extension_test/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("ability_service_extension_test") { "ipc:ipc_napi", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/app_service_extension_test/BUILD.gn b/test/unittest/app_service_extension_test/BUILD.gn index 24a5b62347dfc6f5a35eedcdcbf691dbbc19c9ae..ddb3ff10c523373405a94d06be8ec5e9bc98276d 100644 --- a/test/unittest/app_service_extension_test/BUILD.gn +++ b/test/unittest/app_service_extension_test/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("app_service_extension_test") { "ipc:ipc_napi", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index fad7eeb63e6174abf5247e7cce6b3f0fb1534647..ac1a95f76c51656967ecc7842c3d7bf4d3bb0a8d 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -1915,7 +1915,7 @@ HWTEST_F(MainThreadTest, HandleLaunchAbility_0200, TestSize.Level1) abilityRecord3->abilityInfo_ = nullptr; AbilityRuntime::Runtime::Options options; auto runtime = AbilityRuntime::Runtime::Create(options); - mainThread_->application_->SetRuntime(std::move(runtime)); + mainThread_->application_->AddRuntime(std::move(runtime)); auto contextDeal = std::make_shared(); auto appInfo = std::make_shared(); appInfo->debug = true; diff --git a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp index 53077a41fca2c85d37b6ff7dc0afbef8c85a1faa..68a41952056804096101655207158156ad2d01fc 100644 --- a/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp +++ b/test/unittest/appkit/ohos_application_test/ohos_application_test.cpp @@ -73,7 +73,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnForeground_0100, { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnForeground_0100 start."; ohosApplication_->OnForeground(); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnForeground_0100 end."; } @@ -85,9 +85,9 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnForeground_0100, HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnForeground_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnForeground_0200 start."; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->OnForeground(); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnForeground_0200 end."; } @@ -100,7 +100,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnBackground_0100, { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnBackground_0100 start."; ohosApplication_->OnBackground(); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnBackground_0100 end."; } @@ -112,9 +112,9 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnBackground_0100, HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnBackground_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnBackground_0200 start."; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->OnBackground(); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnBackground_0200 end."; } @@ -174,32 +174,32 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_DumpApplication_030 } /* -* @tc.number: AppExecFwk_OHOSApplicationTest_SetRuntime_0100 -* @tc.name: SetRuntime -* @tc.desc: Verify function SetRuntime pointer runtime empty +* @tc.number: AppExecFwk_OHOSApplicationTest_AddRuntime_0100 +* @tc.name: AddRuntime +* @tc.desc: Verify function AddRuntime pointer runtime empty */ -HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_SetRuntime_0100, TestSize.Level1) +HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddRuntime_0100, TestSize.Level1) { - GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_SetRuntime_0100 start."; + GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddRuntime_0100 start."; std::unique_ptr runtime = nullptr; - ohosApplication_->SetRuntime(std::move(runtime)); + ohosApplication_->AddRuntime(std::move(runtime)); EXPECT_TRUE(runtime == nullptr); - GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_SetRuntime_0100 end."; + GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddRuntime_0100 end."; } /* -* @tc.number: AppExecFwk_OHOSApplicationTest_SetRuntime_0200 -* @tc.name: SetRuntime -* @tc.desc: Verify function SetRuntime pointer runtime_ not empty +* @tc.number: AppExecFwk_OHOSApplicationTest_AddRuntime_0200 +* @tc.name: AddRuntime +* @tc.desc: Verify function AddRuntime pointer runtime_ not empty */ -HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_SetRuntime_0200, TestSize.Level1) +HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddRuntime_0200, TestSize.Level1) { - GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_SetRuntime_0200 start."; + GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddRuntime_0200 start."; std::unique_ptr runtime = std::make_unique(); EXPECT_TRUE(runtime != nullptr); - ohosApplication_->SetRuntime(std::move(runtime)); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); - GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_SetRuntime_0200 end."; + ohosApplication_->AddRuntime(std::move(runtime)); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); + GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddRuntime_0200 end."; } /* @@ -568,7 +568,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_090 bool isAsyncCallback = false; ohosApplication_->abilityRuntimeContext_ = std::make_shared(); ohosApplication_->AddAbilityStage(hapModuleInfo, callback, isAsyncCallback); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); EXPECT_FALSE(ohosApplication_->AddAbilityStage(hapModuleInfo, callback, isAsyncCallback)); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_AddAbilityStage_0900 end."; } @@ -585,7 +585,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_010 auto callback = []() {}; bool isAsyncCallback = false; std::string moduleName = "entry"; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); std::shared_ptr abilityStages = std::make_shared(); ohosApplication_->abilityStages_.emplace(moduleName, abilityStages); ohosApplication_->abilityRuntimeContext_ = std::make_shared(); @@ -606,7 +606,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_011 HapModuleInfo hapModuleInfo; auto callback = []() {}; bool isAsyncCallback = false; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->abilityRuntimeContext_ = std::make_shared(); EXPECT_TRUE(ohosApplication_->abilityStages_.empty()); ohosApplication_->abilityRuntimeContext_ = std::make_shared(); @@ -632,7 +632,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_AddAbilityStage_012 HapModuleInfo hapModuleInfo; auto callback = []() {}; bool isAsyncCallback = false; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->abilityRuntimeContext_ = std::make_shared(); EXPECT_TRUE(ohosApplication_->abilityStages_.empty()); ohosApplication_->abilityRuntimeContext_ = std::make_shared(); @@ -718,7 +718,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_GetAppContext_0100, HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_GetRuntime_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_GetRuntime_0100 start."; - auto &runtime = ohosApplication_->GetRuntime(); + auto &runtime = ohosApplication_->GetRuntime(OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_TRUE(runtime == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_GetRuntime_0100 end."; } @@ -806,7 +806,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyLoadRepairPat const std::string hqfFile = "hqfFile"; const std::string hapPat = "hapPat"; EXPECT_TRUE(ohosApplication_->NotifyLoadRepairPatch(hqfFile, hapPat)); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyLoadRepairPatch_0100 end."; } @@ -820,9 +820,9 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyLoadRepairPat GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyLoadRepairPatch_0200 start."; const std::string hqfFile = "hqfFile"; const std::string hapPath = "hapPath"; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->NotifyLoadRepairPatch(hqfFile, hapPath); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyLoadRepairPatch_0200 end."; } @@ -835,7 +835,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage_0100 start."; ohosApplication_->NotifyHotReloadPage(); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage_0100 end."; } @@ -847,9 +847,9 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage_0200 start."; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); ohosApplication_->NotifyHotReloadPage(); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyHotReloadPage_0200 end."; } @@ -863,7 +863,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairP GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairPatch_0100 start."; std::string hqfFile = "hqfFile"; ohosApplication_->NotifyUnLoadRepairPatch(hqfFile); - EXPECT_TRUE(ohosApplication_->runtime_ == nullptr); + EXPECT_TRUE(ohosApplication_->runtimes_.empty()); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairPatch_0100 end."; } @@ -875,10 +875,10 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairP HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairPatch_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairPatch_0200 start."; - ohosApplication_->runtime_ = std::make_unique(); + ohosApplication_->runtimes_.push_back(std::make_unique()); std::string hqfFile = "entry"; ohosApplication_->NotifyUnLoadRepairPatch(hqfFile); - EXPECT_TRUE(ohosApplication_->runtime_ != nullptr); + EXPECT_TRUE(!(ohosApplication_->runtimes_.empty())); GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_NotifyUnLoadRepairPatch_0200 end."; } diff --git a/test/unittest/cj_ability_delegator_args_test/cj_ability_delegator_args_test.cpp b/test/unittest/cj_ability_delegator_args_test/cj_ability_delegator_args_test.cpp index e73ec53dc3340c296753932fff3e8569fedbdf50..9f5513e7a91ed9dd7d8b9857dade75c0fb4e21cf 100644 --- a/test/unittest/cj_ability_delegator_args_test/cj_ability_delegator_args_test.cpp +++ b/test/unittest/cj_ability_delegator_args_test/cj_ability_delegator_args_test.cpp @@ -101,7 +101,8 @@ void CjAbilityDelegatorArgsTest::TearDown() HWTEST_F(CjAbilityDelegatorArgsTest, CjAbilityDelegatorArgsTestFfiAbilityDelegatorRegistryGetArguments_001, TestSize.Level1) { - OHOS::AppExecFwk::AbilityDelegatorRegistry::RegisterInstance(nullptr, nullptr); + OHOS::AppExecFwk::AbilityDelegatorRegistry::RegisterInstance(nullptr, nullptr, + OHOS::AbilityRuntime::Runtime::Language::CJ); auto result = FfiAbilityDelegatorRegistryGetArguments(); EXPECT_TRUE(result == INVALID_ARG); } @@ -114,7 +115,8 @@ HWTEST_F(CjAbilityDelegatorArgsTest, HWTEST_F(CjAbilityDelegatorArgsTest, CjAbilityDelegatorArgsTestFfiAbilityDelegatorRegistryGetArguments_002, TestSize.Level1) { - OHOS::AppExecFwk::AbilityDelegatorRegistry::RegisterInstance(abilityDelegator_, abilityDelegatorArgs_); + OHOS::AppExecFwk::AbilityDelegatorRegistry::RegisterInstance(abilityDelegator_, abilityDelegatorArgs_, + OHOS::AbilityRuntime::Runtime::Language::CJ); auto result = FfiAbilityDelegatorRegistryGetArguments(); EXPECT_TRUE(result != INVALID_ARG); } diff --git a/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp b/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp index 1bb04bb657c3ff5289e7ba2536b5c3bae17f1598..a3ad0e9e26c80d82e9c017d1ec19f475c8f0731c 100644 --- a/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp +++ b/test/unittest/cj_ability_delegator_test/cj_ability_delegator_test.cpp @@ -125,7 +125,8 @@ void CjAbilityDelegatorTest::TearDown() HWTEST_F(CjAbilityDelegatorTest, CjAbilityDelegatorTestStartAbility_001, TestSize.Level1) { EXPECT_NE(commonDelegator_, nullptr); - AbilityDelegatorRegistry::RegisterInstance(commonDelegator_, delegatorArgs_); + AbilityDelegatorRegistry::RegisterInstance(commonDelegator_, delegatorArgs_, + OHOS::AbilityRuntime::Runtime::Language::CJ); AAFwk::Want want; want.SetElementName(VALUE_TEST_BUNDLE_NAME, ABILITY_NAME); diff --git a/test/unittest/cj_ability_stage_object_test/BUILD.gn b/test/unittest/cj_ability_stage_object_test/BUILD.gn index d81634e4c72c30a6f53c1387a79f1df9a93d84d3..2f3502ed99cbe98ceb670fc22d370db3d1503d20 100644 --- a/test/unittest/cj_ability_stage_object_test/BUILD.gn +++ b/test/unittest/cj_ability_stage_object_test/BUILD.gn @@ -87,6 +87,7 @@ ohos_unittest("cj_ability_stage_object_test") { "napi:cj_bind_native", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/cj_ability_stage_test/BUILD.gn b/test/unittest/cj_ability_stage_test/BUILD.gn index b3fdcf676e730c8a23bf8341685c2b88466ab208..65d21dfbae7f3ba0012fe27c12d5bee63c9da38c 100644 --- a/test/unittest/cj_ability_stage_test/BUILD.gn +++ b/test/unittest/cj_ability_stage_test/BUILD.gn @@ -92,6 +92,7 @@ ohos_unittest("cj_ability_stage_test") { "napi:cj_bind_native", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/cj_ui_ability_test/BUILD.gn b/test/unittest/cj_ui_ability_test/BUILD.gn index 397054358bd89696d87f7f646514a0a102d1b5db..8cb698f7cdad3f3fb865b37d5465d89e0c8307d0 100644 --- a/test/unittest/cj_ui_ability_test/BUILD.gn +++ b/test/unittest/cj_ui_ability_test/BUILD.gn @@ -95,6 +95,7 @@ ohos_unittest("cj_ui_ability_test") { "samgr:samgr_proxy", "window_manager:cj_window_ffi", "window_manager:scene_session", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/dfr_test/watchdog_test/BUILD.gn b/test/unittest/dfr_test/watchdog_test/BUILD.gn index 50b69e464d4954fb765b981281adf912b86ba96c..7d977ca14785d8bdd9e5f2bf001f48a3bcf0deb2 100644 --- a/test/unittest/dfr_test/watchdog_test/BUILD.gn +++ b/test/unittest/dfr_test/watchdog_test/BUILD.gn @@ -84,6 +84,7 @@ ohos_unittest("watchdog_test") { "json:nlohmann_json_static", "jsoncpp:jsoncpp", "napi:ace_napi", + "runtime_core:ani", ] defines = [] diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 513d1f172e90e6b39e228ad014813f4535da2a60..475cb31348ad87bfb25212c2eadea84272afab33 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -123,6 +123,7 @@ ohos_unittest("ability_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -696,6 +697,7 @@ ohos_unittest("ability_impl_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -764,6 +766,7 @@ ohos_unittest("ui_ability_impl_test") { "i18n:intl_util", "input:libmmi-client", "window_manager:libwm", + "runtime_core:ani", ] } } @@ -839,6 +842,7 @@ ohos_unittest("ability_thread_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -923,6 +927,7 @@ ohos_unittest("fa_ability_thread_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1041,6 +1046,7 @@ ohos_unittest("ui_ability_thread_test") { "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1475,6 +1481,7 @@ ohos_unittest("data_ability_impl_test") { "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1541,6 +1548,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1607,6 +1615,7 @@ ohos_unittest("data_ability_impl_file_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1675,6 +1684,7 @@ ohos_unittest("ability_thread_dataability_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1967,6 +1977,7 @@ ohos_unittest("ui_ability_test") { "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -2095,6 +2106,7 @@ ohos_unittest("form_host_client_test") { "resource_management:global_resmgr", "samgr:samgr_proxy", "window_manager:libwm", + "runtime_core:ani", ] } } @@ -2149,6 +2161,7 @@ ohos_unittest("continuation_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -2415,6 +2428,7 @@ ohos_unittest("ability_window_test") { "window_manager:libwm_lite", "window_manager:libwsutils", "window_manager:scene_session", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -2473,6 +2487,7 @@ ohos_unittest("ability_handler_test") { "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -2542,6 +2557,7 @@ ohos_unittest("ability_impl_factory_test") { "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -3425,6 +3441,7 @@ ohos_unittest("ability_second_test") { "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp index 48a66bc11c800743127cd4ea4cc3b2fb6be3f922..c0a65a3feb3d3a7d17672b3ffbf351f06681b10c 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_loader_test.cpp @@ -27,8 +27,8 @@ using namespace OHOS::AppExecFwk; using namespace testing; using namespace testing::ext; using CreateAblity = std::function; -using CreateExtension = std::function; -using CreateUIAblity = std::function; +using CreateExtension = std::function; +using CreateUIAblity = std::function; class AbilityLoaderTest : public testing::Test { public: @@ -136,13 +136,14 @@ HWTEST_F(AbilityLoaderTest, GetExtensionByName_0100, TestSize.Level2) GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0100 start"; std::string abilityName = "AbilityRuntime::Extension"; CreateExtension createFunc; - auto createExtension = []() -> AbilityRuntime::Extension *{ + auto createExtension = [](const std::string &) -> AbilityRuntime::Extension *{ AbilityRuntime::Extension *callBack = new (std::nothrow) AbilityRuntime::Extension; return callBack; }; AbilityLoader::GetInstance().extensions_.clear(); AbilityLoader::GetInstance().RegisterExtension(abilityName, createExtension); - EXPECT_TRUE(AbilityLoader::GetInstance().GetExtensionByName(abilityName) != nullptr); + EXPECT_TRUE(AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) != nullptr); GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0100 end"; } @@ -156,7 +157,8 @@ HWTEST_F(AbilityLoaderTest, GetExtensionByName_0200, TestSize.Level1) GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0200 start"; std::string abilityName = "AbilityRuntime"; AbilityLoader::GetInstance().extensions_.clear(); - EXPECT_FALSE(AbilityLoader::GetInstance().GetExtensionByName(abilityName) != nullptr); + EXPECT_FALSE(AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) != nullptr); GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0200 end"; } @@ -191,13 +193,14 @@ HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0100, TestSize.Level1) GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 start"; std::string abilityName = "UIAbility"; CreateAblity createFunc; - auto createAblity = []() -> AbilityRuntime::UIAbility *{ + auto createAblity = [](const std::string &) -> AbilityRuntime::UIAbility *{ AbilityRuntime::UIAbility *callBack = new (std::nothrow) AbilityRuntime::UIAbility; return callBack; }; AbilityLoader::GetInstance().uiAbilities_.clear(); AbilityLoader::GetInstance().RegisterUIAbility(abilityName, createAblity); - EXPECT_TRUE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr); + EXPECT_TRUE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) != nullptr); GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 end"; } @@ -211,6 +214,7 @@ HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0200, TestSize.Level1) GTEST_LOG_(INFO) << "AbilityLoaderTest GetAbilityByName_0200 start"; std::string abilityName = "UIAbilityName"; AbilityLoader::GetInstance().abilities_.clear(); - EXPECT_FALSE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr); + EXPECT_FALSE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0) != nullptr); GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0200 start"; } \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp index 8217ba8a76fdef54465b23a9878a0aaa1c402cff..96444807b384c8551dfc49552e4b8f665d91d7a1 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_thread_test.cpp @@ -788,7 +788,8 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0100, Function | std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); - auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); + auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_EQ(extension, nullptr); abilitythread->AttachExtension(application, abilityRecord, mainRunner); @@ -815,7 +816,8 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0200, Function | auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, application); - auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); + auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_EQ(extension, nullptr); abilitythread->AttachExtension(application, abilityRecord); @@ -840,7 +842,8 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0201, Function | auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::string abilityName = abilitythread->CreateAbilityName(abilityRecord, nullptr); - auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); + auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_EQ(extension, nullptr); abilitythread->AttachExtension(nullptr, abilityRecord); @@ -860,7 +863,8 @@ HWTEST_F(AbilityThreadTest, AaFwk_AbilityThread_AttachExtension_0202, Function | std::shared_ptr application = std::make_shared(); std::string abilityName = abilitythread->CreateAbilityName(nullptr, application); - auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); + auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_EQ(extension, nullptr); abilitythread->AttachExtension(application, nullptr); diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp index b7fd594f31174d434d0af86feb610f71bc77bb32..5ece1a597b78b935a95c704480aa46c2d481288c 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_ability_thread_test.cpp @@ -1000,7 +1000,8 @@ HWTEST_F( auto abilityRecord = std::make_shared(abilityInfo, token, nullptr, 0); std::shared_ptr mainRunner = EventRunner::Create(abilityInfo->name); std::string abilityName = extensionabilitythread->CreateAbilityName(abilityRecord, application); - auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName); + auto extension = AbilityLoader::GetInstance().GetExtensionByName(abilityName, + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0); EXPECT_EQ(extension, nullptr); GTEST_LOG_(INFO) << "ExtensionAbilityThread_CreateAbilityName_0100 end"; } diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 0baadfbaedab2dd43ad33c44b0ace15b45890149..0613821abf7296e02ac8514eaa4a3949cd6ac86b 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -142,6 +142,7 @@ ohos_unittest("application_test") { "resource_management:global_resmgr", "resource_management:librawfile", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -207,6 +208,7 @@ ohos_unittest("context_impl_test") { "resource_management:global_resmgr", "resource_management:librawfile", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -265,6 +267,7 @@ ohos_unittest("context_impl_second_test") { "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -325,6 +328,7 @@ ohos_unittest("context_impl_third_test") { "resource_management:global_resmgr", "resource_management:librawfile", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -375,6 +379,7 @@ ohos_unittest("context_container_test") { "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -576,6 +581,7 @@ ohos_unittest("context_deal_test") { "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -631,6 +637,7 @@ ohos_unittest("application_impl_test") { "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -776,6 +783,7 @@ ohos_unittest("form_extension_context_test") { "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -908,6 +916,7 @@ ohos_unittest("assert_fault_test") { "init:libbegetutil", "ipc:ipc_core", "napi:ace_napi", + "runtime_core:ani", ] if (ability_runtime_graphics) { @@ -1023,6 +1032,7 @@ ohos_unittest("idle_time_test") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", + "runtime_core:ani", ] } @@ -1061,6 +1071,7 @@ ohos_unittest("dump_runtime_helper_second_test") { "napi:ace_napi", "ffrt:libffrt", "storage_service:storage_manager_acl", + "runtime_core:ani", ] } diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn index d23b04bbb7d7aee9adfa72ecca1bf65b02e6d897..93ebc7c877974f4d753ba9b7ea1ccf7078e9f401 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn @@ -210,6 +210,7 @@ ohos_unittest("ability_delegator_registry_unittest") { "init:libbegetutil", "ipc:ipc_core", "napi:ace_napi", + "runtime_core:ani", ] } diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_registry_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_registry_test.cpp index 46e6d35f182b8b30adc2582b7308261ad15e5cca..c6afcd5fbacb8a54e3ba6eb28995ce5bd4dbd5ed 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_registry_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_registry_test.cpp @@ -96,8 +96,10 @@ HWTEST_F(AbilityDelegatorRegistryTest, Ability_Delegator_Registry_Test_0100, Fun std::unique_ptr testRunner = TestRunner::Create(nullptr, abilityArgs, true); std::shared_ptr abilityDelegator = std::make_shared(nullptr, std::move(testRunner), nullptr); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); - EXPECT_EQ(AbilityDelegatorRegistry::GetAbilityDelegator(), abilityDelegator); + EXPECT_EQ(AbilityDelegatorRegistry::GetAbilityDelegator(OHOS::AbilityRuntime::Runtime::Language::JS), + abilityDelegator); EXPECT_EQ(AbilityDelegatorRegistry::GetArguments(), abilityArgs); } diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_test.cpp index 0be170a4d02becdf8e69c623165f5b4a1b82f045..59ed7bb9521a54931f98bc217b5d89883ac81331 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/ability_delegator_test.cpp @@ -202,7 +202,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0100, Function | MediumTes std::shared_ptr abilityArgs = std::make_shared(want); std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -241,7 +242,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0200, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -276,7 +278,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0300, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -306,7 +309,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0400, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -338,7 +342,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0500, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -376,7 +381,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0600, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -409,7 +415,8 @@ HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_070, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2()); @@ -460,7 +467,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_0800, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -495,7 +503,8 @@ HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_0900, Function | MediumTe std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2()); @@ -527,7 +536,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1000, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -557,7 +567,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1100, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -592,7 +603,8 @@ HWTEST_F(AbilityDelegatorTest2, Ability_Delegator_Test_1200, Function | MediumTe std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2()); @@ -624,7 +636,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1300, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -654,7 +667,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1400, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -684,7 +698,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1500, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -715,7 +730,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1600, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -747,7 +763,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1700, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -780,7 +797,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1800, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -813,7 +831,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_1900, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -852,7 +871,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2000, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -890,7 +910,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2100, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -923,7 +944,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2200, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -963,7 +985,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_23400, Function | MediumTe std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -996,7 +1019,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2400, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1036,7 +1060,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2500, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1069,7 +1094,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2600, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1109,7 +1135,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2700, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1142,7 +1169,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2800, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1182,7 +1210,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_2900, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1215,7 +1244,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3000, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1255,7 +1285,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3100, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1294,7 +1325,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3200, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1334,7 +1366,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3300, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1373,7 +1406,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3400, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -1416,13 +1450,15 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3500, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); abilityDelegator->abilityMonitors_.clear(); std::shared_ptr mockMonitor = std::make_shared(ABILITY_NAME); @@ -1461,13 +1497,15 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3600, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub2); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); abilityDelegator->abilityMonitors_.clear(); std::shared_ptr mockMonitor = std::make_shared(ABILITY_NAME); @@ -1504,7 +1542,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3700, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1535,7 +1574,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3800, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1566,7 +1606,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_3900, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1597,7 +1638,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4000, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1628,7 +1670,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4100, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1660,7 +1703,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4200, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1693,7 +1737,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4300, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1727,7 +1772,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4400, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1760,7 +1806,8 @@ HWTEST_F(AbilityDelegatorTest, Ability_Delegator_Test_4500, Function | MediumTes std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new AAFwk::MockTestObserverStub); @@ -1903,7 +1950,8 @@ HWTEST_F(AbilityDelegatorTest, StartAbilityTest_0100, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "test start."); ASSERT_NE(commonDelegator_, nullptr); - AbilityDelegatorRegistry::RegisterInstance(commonDelegator_, delegatorArgs_); + AbilityDelegatorRegistry::RegisterInstance(commonDelegator_, delegatorArgs_, + OHOS::AbilityRuntime::Runtime::Language::JS); AAFwk::Want want; want.SetElementName(VALUE_TEST_BUNDLE_NAME, ABILITY_NAME); diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp index 1528289697c2e4642a5e74bacb5c7417d7f44f62..f990ee23840277cd5aa4ed5cafad1040727d3cf6 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp @@ -111,7 +111,8 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0100, Function | MediumTest | Lev } std::shared_ptr abilityArgs = std::make_shared(want); - AbilityDelegatorRegistry::RegisterInstance(nullptr, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(nullptr, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); JsTestRunner* jsRunnerdrive = nullptr; jsRunnerdrive->ReportFinished(REPORT_FINISH_MSG); @@ -144,14 +145,16 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0200, Function | MediumTest | Lev std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); EXPECT_TRUE(testRunner->Initialize()); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); JsTestRunner* jsRunnerdrive = nullptr; jsRunnerdrive->ReportFinished(REPORT_FINISH_MSG); @@ -181,11 +184,13 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0300, Function | MediumTest | Lev } std::shared_ptr abilityArgs = std::make_shared(want); - AbilityDelegatorRegistry::RegisterInstance(nullptr, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(nullptr, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), std::make_shared(want), true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub()); @@ -224,13 +229,15 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0400, Function | MediumTest | Lev std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); sptr shobserver = sptr(new MockTestObserverStub); abilityDelegator->observer_ = shobserver; @@ -266,13 +273,15 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0500, Function | MediumTest | Lev std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); JsTestRunner* pTestRunner = static_cast(static_cast((testRunner.get()))); pTestRunner->ReportFinished(REPORT_FINISH_MSG); @@ -305,13 +314,15 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0600, Function | MediumTest | Lev std::shared_ptr context = std::make_shared(); std::unique_ptr testRunner = TestRunner::Create( - std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime( + OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), abilityArgs, true); sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); std::shared_ptr abilityDelegator = std::make_shared(context, std::move(testRunner), iRemoteObj); - AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); sptr shobserver = sptr(new MockTestObserverStub); abilityDelegator->observer_ = shobserver; diff --git a/test/unittest/frameworks_kits_appkit_native_test/dump_runtime_helper_second_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/dump_runtime_helper_second_test.cpp index 7be5fffd660c211e6afde18e6392abf0752c7a7e..f93adbc173c09f9c5aa869374eba5e7e9338d217 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/dump_runtime_helper_second_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/dump_runtime_helper_second_test.cpp @@ -79,7 +79,7 @@ HWTEST_F(DumpRuntimeHelperTestSecond, SetAppFreezeFilterCallback_0200, TestSize. AbilityRuntime::Runtime::Options options; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); helper = std::make_shared(application); helper->SetAppFreezeFilterCallback(); EXPECT_NE(application, nullptr); @@ -117,7 +117,7 @@ HWTEST_F(DumpRuntimeHelperTestSecond, DumpJsHeap_0400, TestSize.Level1) AbilityRuntime::Runtime::Options options; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); helper = std::make_shared(application); helper->DumpJsHeap(info); EXPECT_NE(application, nullptr); @@ -146,9 +146,10 @@ HWTEST_F(DumpRuntimeHelperTestSecond, GetCheckList_0500, TestSize.Level1) AbilityRuntime::Runtime::Options options; options.lang = AbilityRuntime::Runtime::Language::JS; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); auto helper = std::make_shared(application); - helper->GetCheckList(helper->application_->GetRuntime(), checkList); + helper->GetCheckList(helper->application_->GetRuntime(OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0), + checkList); EXPECT_NE(checkList, ""); } @@ -164,7 +165,7 @@ HWTEST_F(DumpRuntimeHelperTestSecond, GetJsLeakModule_0600, TestSize.Level1) AbilityRuntime::Runtime::Options options; options.lang = AbilityRuntime::Runtime::Language::JS; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); auto helper = std::make_shared(application); napi_env env = nullptr; napi_value global = nullptr; @@ -185,10 +186,10 @@ HWTEST_F(DumpRuntimeHelperTestSecond, GetJsLeakModule_0700, TestSize.Level1) AbilityRuntime::Runtime::Options options; options.lang = AbilityRuntime::Runtime::Language::JS; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); auto helper = std::make_shared(application); AbilityRuntime::JsRuntime &jsruntime = static_cast( - *helper->application_->GetRuntime()); + *helper->application_->GetRuntime(OHOS::AbilityRuntime::CODE_LANGUAGE_ARKTS_1_0)); AbilityRuntime::HandleScope handleScope(jsruntime); auto env = jsruntime.GetNapiEnv(); napi_value global = nullptr; @@ -209,7 +210,7 @@ HWTEST_F(DumpRuntimeHelperTestSecond, GetMethodCheck_0800, TestSize.Level1) AbilityRuntime::Runtime::Options options; options.lang = AbilityRuntime::Runtime::Language::JS; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); auto helper = std::make_shared(application); napi_env env = nullptr; napi_value global = nullptr; @@ -231,7 +232,7 @@ HWTEST_F(DumpRuntimeHelperTestSecond, WriteCheckList_0900, TestSize.Level1) AbilityRuntime::Runtime::Options options; options.lang = AbilityRuntime::Runtime::Language::JS; auto runtime = AbilityRuntime::Runtime::Create(options); - application->SetRuntime(std::move(runtime)); + application->AddRuntime(std::move(runtime)); auto helper = std::make_shared(application); std::string checkList = "test"; helper->WriteCheckList(checkList);