From 8f4ea44f1d08e42e317fc1c73ebc7461f5420e91 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Thu, 11 Sep 2025 09:57:48 +0800 Subject: [PATCH] code: add live form extension 1.2 Signed-off-by: zhangzezhong --- BUILD.gn | 2 + .../ani/live_form_extension_ability/BUILD.gn | 48 ++++++++++ ...ohos.app.form.LiveFormExtensionAbility.ets | 32 +++++++ .../application/LiveFormExtensionContext.ets | 20 ++++ .../include/ets_live_form_extension.h | 63 ++++++++++++ .../include/ets_live_form_extension_context.h | 43 +++++++++ .../include/ets_live_form_extension_impl.h | 51 ++++++++++ .../ets_live_form_extension_instance.h | 28 ++++++ .../src/ets_live_form_extension.cpp | 96 +++++++++++++++++++ .../src/ets_live_form_extension_context.cpp | 66 +++++++++++++ .../src/ets_live_form_extension_impl.cpp | 64 +++++++++++++ .../src/ets_live_form_extension_instance.cpp | 54 +++++++++++ frameworks/js/napi/BUILD.gn | 54 ++++++++++- .../live_form_extension.cpp | 3 + 14 files changed, 623 insertions(+), 1 deletion(-) create mode 100644 frameworks/ets/ani/live_form_extension_ability/BUILD.gn create mode 100644 frameworks/ets/ani/live_form_extension_ability/ets/@ohos.app.form.LiveFormExtensionAbility.ets create mode 100644 frameworks/ets/ani/live_form_extension_ability/ets/application/LiveFormExtensionContext.ets create mode 100644 frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension.h create mode 100644 frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_context.h create mode 100644 frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_impl.h create mode 100644 frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_instance.h create mode 100644 frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension.cpp create mode 100644 frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_context.cpp create mode 100644 frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_impl.cpp create mode 100644 frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_instance.cpp diff --git a/BUILD.gn b/BUILD.gn index b07a2581ea..f0c02046a7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -560,6 +560,8 @@ group("form_ani_packages") { "${form_fwk_ani_path}/form_info:form_info_etc", "${form_fwk_ani_path}/form_error:form_error_etc", "${form_fwk_ani_path}/form_util:formutil_ani", + "${form_fwk_ani_path}/live_form_extension_ability:live_form_extension_ability_etc", + "${form_fwk_ani_path}/live_form_extension_ability:live_form_extension_context_etc", "${form_fwk_ani_path}/utils:util_ani", ] } diff --git a/frameworks/ets/ani/live_form_extension_ability/BUILD.gn b/frameworks/ets/ani/live_form_extension_ability/BUILD.gn new file mode 100644 index 0000000000..73d48f2c7b --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/ability/form_fwk/form_fwk.gni") + +generate_static_abc("live_form_extension_ability") { + base_url = "./ets" + files = [ "./ets/@ohos.app.form.LiveFormExtensionAbility.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/live_form_extension_ability.abc" +} + +ohos_prebuilt_etc("live_form_extension_ability_etc") { + source = "$target_out_dir/live_form_extension_ability.abc" + deps = [ ":live_form_extension_ability" ] + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "form_fwk" +} + +generate_static_abc("live_form_extension_context") { + base_url = "./ets" + files = [ "./ets/application/LiveFormExtensionContext.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/live_form_extension_context.abc" +} + +ohos_prebuilt_etc("live_form_extension_context_etc") { + source = "$target_out_dir/live_form_extension_context.abc" + deps = [ ":live_form_extension_context" ] + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "form_fwk" +} \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/ets/@ohos.app.form.LiveFormExtensionAbility.ets b/frameworks/ets/ani/live_form_extension_ability/ets/@ohos.app.form.LiveFormExtensionAbility.ets new file mode 100644 index 0000000000..b4b6d67b26 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/ets/@ohos.app.form.LiveFormExtensionAbility.ets @@ -0,0 +1,32 @@ +/* + * 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 ExtensionAbility from '@ohos.app.ability.ExtensionAbility'; +import LiveFormExtensionContext from 'application.LiveFormExtensionContext'; +import type UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import formInfo from '@ohos.app.form.formInfo'; + +export interface LiveFormInfo { + formId: string; + rect: formInfo.Rect; + borderRadius: number; +} + +declare class LiveFormExtensionAbility extends ExtensionAbility { + public context: LiveFormExtensionContext; + onLiveFormCreate(liveFormInfo: LiveFormInfo, session: UIExtensionContentSession): void; + onLiveFormDestroy(liveFormInfo: LiveFormInfo): void; +} +export default LiveFormExtensionAbility; diff --git a/frameworks/ets/ani/live_form_extension_ability/ets/application/LiveFormExtensionContext.ets b/frameworks/ets/ani/live_form_extension_ability/ets/application/LiveFormExtensionContext.ets new file mode 100644 index 0000000000..2df0ec1930 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/ets/application/LiveFormExtensionContext.ets @@ -0,0 +1,20 @@ +/* + * 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'; + +declare class LiveFormExtensionContext extends ExtensionContext { +} +export default LiveFormExtensionContext; diff --git a/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension.h b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension.h new file mode 100644 index 0000000000..938c6c65b5 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension.h @@ -0,0 +1,63 @@ +/* + * 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_FORM_FWK_ETS_LIVE_FORM_EXTENSION_H +#define OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_H + +#include "configuration.h" +#include "ets_ui_extension_base.h" +#include "live_form_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +class EtsRuntime; +class EtsLiveFormExtensionImpl; + +/** + * @brief Basic live form extension components. + */ +class EtsLiveFormExtension : public LiveFormExtension, + public std::enable_shared_from_this { +public: + explicit EtsLiveFormExtension(const std::unique_ptr &runtime); + + ~EtsLiveFormExtension() override = default; + + /** + * @brief Init the live form extension. + * + * @param record the live form extension record. + * @param application the application info. + * @param handler the live form extension handler. + * @param token the remote token. + */ + void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, const sptr &token) override; + + /** + * @brief Create EtsLiveFormExtension. + * + * @param runtime The runtime. + * @return The EtsLiveFormExtension instance. + */ + static EtsLiveFormExtension *Create(const std::unique_ptr &runtime); + +private: + std::shared_ptr impl_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_H \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_context.h b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_context.h new file mode 100644 index 0000000000..88efa23460 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_context.h @@ -0,0 +1,43 @@ +/* + * 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_FORM_FWK_ETS_LIVE_FORM_EXTENSION_CONTEXT_H +#define OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_CONTEXT_H + +#include "ani.h" +#include "live_form_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +class EtsLiveFormExtensionContext { +public: + explicit EtsLiveFormExtensionContext(const std::shared_ptr &context) + : context_(context) + {} + + virtual ~EtsLiveFormExtensionContext() = default; + + static ani_object CreateEtsLiveFormExtensionContext(ani_env *env, + std::shared_ptr context); + +private: + static EtsLiveFormExtensionContext* GetEtsLiveFormExtensionContext(ani_env *env, ani_object obj); +private: + std::weak_ptr context_; +}; +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_CONTEXT_H \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_impl.h b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_impl.h new file mode 100644 index 0000000000..8f0699d36a --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_impl.h @@ -0,0 +1,51 @@ +/* + * 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_FORM_FWK_ETS_LIVE_FORM_EXTENSION_IMPL_H +#define OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_IMPL_H + +#include "ets_ui_extension_base.h" +#include "live_form_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { + +class LiveFormExtensionContext; + +class EtsLiveFormExtensionImpl : public EtsUIExtensionBase { +public: + explicit EtsLiveFormExtensionImpl(const std::unique_ptr &runtime); + ~EtsLiveFormExtensionImpl() override = default; + + void SetContext(const std::shared_ptr &context) + { + context_ = context; + EtsUIExtensionBase::SetContext(context); + } + +protected: + void BindContext() override; + +protected: + std::shared_ptr context_ = nullptr; + +private: + ETSRuntime &etsRuntime_; + using EtsUIExtensionBase::SetContext; +}; +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_FORM_FWK_ETS_LIVE_FORM_EXTENSION_IMPL_H \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_instance.h b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_instance.h new file mode 100644 index 0000000000..dfd47148ce --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/include/ets_live_form_extension_instance.h @@ -0,0 +1,28 @@ +/* + * 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_FORM_FWK__ETS_LIVE_FORM_EXTENSION_INSTANCE_H +#define OHOS_FORM_FWK__ETS_LIVE_FORM_EXTENSION_INSTANCE_H + +#include "live_form_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +class Runtime; + +LiveFormExtension *CreateETSLiveFormExtension(const std::unique_ptr &runtime); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_FORM_FWK__ETS_LIVE_FORM_EXTENSION_INSTANCE_H \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension.cpp b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension.cpp new file mode 100644 index 0000000000..e9f81e15a5 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension.cpp @@ -0,0 +1,96 @@ +/* + * 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_live_form_extension.h" +#include "hitrace_meter.h" +#include "ets_ui_extension_base.h" +#include "fms_log_wrapper.h" +#include "ets_live_form_extension_context.h" +#include "ets_live_form_extension_impl.h" + +#ifdef WINDOWS_PLATFORM +#define ETS_EXPORT __declspec(dllexport) +#else +#define ETS_EXPORT __attribute__((visibility("default"))) +#endif + +namespace OHOS { +namespace AbilityRuntime { + +EtsLiveFormExtension *EtsLiveFormExtension::Create(const std::unique_ptr &runtime) +{ + return new (std::nothrow) EtsLiveFormExtension(runtime); +} + +EtsLiveFormExtension::EtsLiveFormExtension(const std::unique_ptr &runtime) +{ + impl_ = std::make_shared(runtime); + SetUIExtensionBaseImpl(impl_); +} + +void EtsLiveFormExtension::Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) +{ + HILOG_DEBUG("Begin init live form extension"); + if (record == nullptr) { + HILOG_ERROR("null record"); + return; + } + + auto appContext = Context::GetApplicationContext(); + if (appContext == nullptr) { + HILOG_ERROR("null appContext"); + return; + } + + if (impl_ == nullptr) { + HILOG_ERROR("null impl_"); + return; + } + + std::shared_ptr context = std::make_shared(); + context->SetToken(token); + context->SetApplicationInfo(appContext->GetApplicationInfo()); + context->SetResourceManager(appContext->GetResourceManager()); + context->SetParentContext(appContext); + + auto abilityInfo = record->GetAbilityInfo(); + context->SetAbilityInfo(abilityInfo); + context->InitHapModuleInfo(abilityInfo); + context->SetConfiguration(appContext->GetConfiguration()); + if (abilityInfo->applicationInfo.multiProjects) { + std::shared_ptr moduleContext = context->CreateModuleContext(abilityInfo->moduleName); + if (moduleContext != nullptr) { + auto rm = moduleContext->GetResourceManager(); + context->SetResourceManager(rm); + } + } + + Extension::Init(record, application, handler, token); + impl_->SetContext(context); + impl_->SetAbilityInfo(Extension::abilityInfo_); + auto extensionCommon = impl_->Init(record, application, handler, token); + ExtensionBase::SetExtensionCommon(extensionCommon); +} +} // namespace AbilityRuntime +} // namespace OHOS + +ETS_EXPORT extern "C" OHOS::AbilityRuntime::LiveFormExtension *OHOS_ETS_Live_Form_Extension_Create( + const std::unique_ptr &runtime) +{ + return OHOS::AbilityRuntime::EtsLiveFormExtension::Create(runtime); +} \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_context.cpp b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_context.cpp new file mode 100644 index 0000000000..2ed4d9ddde --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_context.cpp @@ -0,0 +1,66 @@ +/* + * 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_live_form_extension_context.h" +#include "ets_ui_extension_context.h" +#include "ets_runtime.h" +#include "ani_common_util.h" +#include "ani_common_want.h" +#include "element_name.h" +#include "fms_log_wrapper.h" +#include "form_constants.h" +#include "form_errors.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +const char *LIVE_FORM_EXTENSION_CONTEXT = "C{application.LiveFormExtensionContext.LiveFormExtensionContext}"; +} // namespace +using namespace OHOS::AppExecFwk; + +EtsLiveFormExtensionContext* EtsLiveFormExtensionContext::GetEtsLiveFormExtensionContext(ani_env *env, ani_object obj) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "null env"); + return nullptr; + } + EtsLiveFormExtensionContext *etsContext = nullptr; + ani_status status = ANI_ERROR; + ani_long etsContextLong = 0; + if ((status = env->Object_GetFieldByName_Long(obj, "nativeExtensionContext", &etsContextLong)) != ANI_OK) { + TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); + return nullptr; + } + etsContext = reinterpret_cast(etsContextLong); + if (etsContext == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "etsContext null"); + return nullptr; + } + return etsContext; +} +ani_object EtsLiveFormExtensionContext::CreateEtsLiveFormExtensionContext( + ani_env *env, std::shared_ptr context) +{ + HILOG_DEBUG("begin"); + std::shared_ptr abilityInfo = nullptr; + if (context) { + abilityInfo = context->GetAbilityInfo(); + } + ani_object contextObj = AbilityRuntime::CreateEtsUIExtensionContext(env, context); + return contextObj; +} + +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_impl.cpp b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_impl.cpp new file mode 100644 index 0000000000..781b46bde1 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_impl.cpp @@ -0,0 +1,64 @@ +/* + * 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_live_form_extension_impl.h" +#include "ani.h" +#include "ets_ui_extension_content_session.h" +#include "ani_common_want.h" +#include "fms_log_wrapper.h" +#include "ets_live_form_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { + +EtsLiveFormExtensionImpl::EtsLiveFormExtensionImpl(const std::unique_ptr &runtime) + : EtsUIExtensionBase(runtime), etsRuntime_(static_cast(*runtime)) +{} + +void EtsLiveFormExtensionImpl::BindContext() +{ + if (etsObj_ == nullptr) { + HILOG_ERROR("null etsObj_"); + return; + } + auto *env = etsRuntime_.GetAniEnv(); + if (env == nullptr) { + HILOG_ERROR("null env"); + return; + } + ani_object contextObj = EtsLiveFormExtensionContext::CreateEtsLiveFormExtensionContext(env, context_); + if (contextObj == nullptr) { + HILOG_ERROR("null contextObj"); + return; + } + ani_field contextField; + auto status = env->Class_FindField(etsObj_->aniCls, "context", &contextField); + if (status != ANI_OK) { + HILOG_ERROR("Class_GetField context failed"); + return; + } + ani_ref contextRef = nullptr; + if (env->GlobalReference_Create(contextObj, &contextRef) != ANI_OK) { + HILOG_ERROR("GlobalReference_Create contextObj failed"); + return; + } + if (env->Object_SetField_Ref(etsObj_->aniObj, contextField, contextRef) != ANI_OK) { + HILOG_ERROR("Object_SetField_Ref contextObj failed"); + } + context_->Bind(etsRuntime_, &contextRef); + HILOG_ERROR("BindContext end"); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_instance.cpp b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_instance.cpp new file mode 100644 index 0000000000..8f7a80f472 --- /dev/null +++ b/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_instance.cpp @@ -0,0 +1,54 @@ +/* + * 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_live_form_extension_instance.h" + +#include +#include + +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "string_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +const char *ETS_ANI_LIBNAME = "liblive_form_extension_ani.z.so"; +const char *ETS_ANI_CREATE_FUNC = "OHOS_ETS_Live_Form_Extension_Create"; +using CreateCreateETSLiveFormExtensionFunc = LiveFormExtension*(*)(const std::unique_ptr&); +CreateCreateETSLiveFormExtensionFunc g_etsCreateFunc = nullptr; +} + +LiveFormExtension *CreateETSLiveFormExtension(const std::unique_ptr &runtime) +{ + if (g_etsCreateFunc != nullptr) { + return g_etsCreateFunc(runtime); + } + auto handle = dlopen(ETS_ANI_LIBNAME, RTLD_LAZY); + if (handle == nullptr) { + HILOG_ERROR("dlopen failed %{public}s, %{public}s", ETS_ANI_LIBNAME, dlerror()); + return nullptr; + } + auto symbol = dlsym(handle, ETS_ANI_CREATE_FUNC); + if (symbol == nullptr) { + HILOG_ERROR("dlsym failed %{public}s, %{public}s", ETS_ANI_CREATE_FUNC, dlerror()); + dlclose(handle); + return nullptr; + } + g_etsCreateFunc = reinterpret_cast(symbol); + return g_etsCreateFunc(runtime); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 856493c3cb..230598a0aa 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -957,7 +957,11 @@ ohos_shared_library("live_form_extension") { cfi_cross_dso = true debug = false } - include_dirs = [ "live_form_extension_context" ] + include_dirs = [ + "live_form_extension_context", + "live_form_extension_ability", + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/include/", + ] sources = [ "live_form_extension_ability/js_live_form_extension.cpp", @@ -965,6 +969,7 @@ ohos_shared_library("live_form_extension") { "live_form_extension_context/js_live_form_extension_context.cpp", "live_form_extension_context/js_live_form_extension_impl.cpp", "live_form_extension_context/live_form_extension_context.cpp", + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_instance.cpp", ] configs = [ ":fmskit_config" ] @@ -1034,3 +1039,50 @@ ohos_shared_library("live_form_extension_module") { subsystem_name = "ability" part_name = "form_fwk" } + +ohos_shared_library("live_form_extension_ani") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ + "live_form_extension_context/", + "live_form_extension_ability/", + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/include/",] + + sources = [ + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_context.cpp", + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension_impl.cpp", + "${form_fwk_path}/frameworks/ets/ani/live_form_extension_ability/src/ets_live_form_extension.cpp", + ] + + configs = [ ":fmskit_config" ] + + deps = [ + ":live_form_extension", + "${form_fwk_ani_path}/utils:util_ani", + "${form_fwk_path}:fmskit_native", + "${form_fwk_path}:fmskit_provider_client", + "${form_fwk_path}:form_manager", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ani_common", + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_context", + "ability_runtime:runtime", + "ability_runtime:ui_extension", + "ability_runtime:ui_extension_ani", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "runtime_core:ani", + ] + + subsystem_name = "ability" + part_name = "form_fwk" +} diff --git a/frameworks/js/napi/live_form_extension_ability/live_form_extension.cpp b/frameworks/js/napi/live_form_extension_ability/live_form_extension.cpp index 85cb9be064..5a2f059e8e 100644 --- a/frameworks/js/napi/live_form_extension_ability/live_form_extension.cpp +++ b/frameworks/js/napi/live_form_extension_ability/live_form_extension.cpp @@ -17,6 +17,7 @@ #include "runtime.h" #include "fms_log_wrapper.h" #include "js_live_form_extension.h" +#include "ets_live_form_extension_instance.h" namespace OHOS { namespace AbilityRuntime { @@ -34,6 +35,8 @@ LiveFormExtension *LiveFormExtension::Create(const std::unique_ptr &run switch (runtime->GetLanguage()) { case Runtime::Language::JS: return JsLiveFormExtension::Create(runtime); + case Runtime::Language::ETS: + return CreateETSLiveFormExtension(runtime); default: return new LiveFormExtension(); } -- Gitee