diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index eb890b76a3540ee42b12c0aa73148d379edad401..6fc2b26ed9041f3a0bdb60ca775d04ee74f19420 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -18,6 +18,8 @@ group("ani_packages") { deps = [ "${ability_runtime_path}/frameworks/ets/ani/ability_delegator:ability_delegator_registry_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/ability_manager:ability_manager_ani_kit", + "${ability_runtime_path}/frameworks/ets/ani/action_extension_ability:action_extension_ani", + "${ability_runtime_path}/frameworks/ets/ani/share_extension_ability:share_extension_ani", "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", "${ability_runtime_path}/frameworks/ets/ani/ani_mission_manager:missionmanager_ani", "${ability_runtime_path}/frameworks/ets/ani/ani_wantagent_common:ani_wantagent_common", diff --git a/frameworks/ets/ani/action_extension_ability/BUILD.gn b/frameworks/ets/ani/action_extension_ability/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..db3506af9894b56d7a2ae24b7b4f8263114cf7e5 --- /dev/null +++ b/frameworks/ets/ani/action_extension_ability/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("action_extension_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + include_dirs = [ + "./include", + "${ability_runtime_path}/frameworks/ets/ani/action_extension_ability/include", + "${ability_runtime_path}/frameworks/ets/ani/ui_extension_ability/include", + "${ability_runtime_path}/frameworks/ets/ani/ui_extension_base/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/action_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base", + ] + + configs = [] + + public_configs = [] + + sources = [ "./src/ets_action_extension.cpp" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:action_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", + "${ability_runtime_native_path}/ability/native:ui_extension_ani", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_napi", + "ipc:ipc_single", + "napi:ace_napi", + "runtime_core:ani", + ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/ets/ani/action_extension_ability/include/ets_action_extension.h b/frameworks/ets/ani/action_extension_ability/include/ets_action_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..41ebdacb90d3c20f435efb9e253ff583c73fffcc --- /dev/null +++ b/frameworks/ets/ani/action_extension_ability/include/ets_action_extension.h @@ -0,0 +1,36 @@ +/* + * 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_ACTION_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_ETS_ACTION_EXTENSION_H + +#include "action_extension.h" +#include "configuration.h" + +namespace OHOS { +namespace AbilityRuntime { +class ActionExtension; +class EtsUIExtensionBase; + +class EtsActionExtension : public ActionExtension, public std::enable_shared_from_this { +public: + explicit EtsActionExtension(const std::unique_ptr &runtime); + virtual ~EtsActionExtension() override; + + static EtsActionExtension *Create(const std::unique_ptr &runtime); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_ACTION_EXTENSION_H diff --git a/frameworks/ets/ani/action_extension_ability/include/ets_action_extension_instance.h b/frameworks/ets/ani/action_extension_ability/include/ets_action_extension_instance.h new file mode 100644 index 0000000000000000000000000000000000000000..9d624198a03d34995c0ee3c4cc474ca4006fafab --- /dev/null +++ b/frameworks/ets/ani/action_extension_ability/include/ets_action_extension_instance.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_ETS_ACTION_EXTENSION_INSTANCE_H +#define OHOS_ABILITY_RUNTIME_ETS_ACTION_EXTENSION_INSTANCE_H + +#include "action_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +class ActionExtension; +class Runtime; + +ActionExtension *CreateETSActionExtension(const std::unique_ptr &runtime); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_ACTION_EXTENSION_INSTANCE_H \ No newline at end of file diff --git a/frameworks/ets/ani/action_extension_ability/src/ets_action_extension.cpp b/frameworks/ets/ani/action_extension_ability/src/ets_action_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..51ede138c8af966cad942dda6ccd7925ed87ad46 --- /dev/null +++ b/frameworks/ets/ani/action_extension_ability/src/ets_action_extension.cpp @@ -0,0 +1,52 @@ +/* + * 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_action_extension.h" + +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "ets_ui_extension_base.h" + +#ifdef WINDOWS_PLATFORM +#define ETS_EXPORT __declspec(dllexport) +#else +#define ETS_EXPORT __attribute__((visibility("default"))) +#endif + +namespace OHOS { +namespace AbilityRuntime { +EtsActionExtension *EtsActionExtension::Create(const std::unique_ptr &runtime) +{ + return new (std::nothrow) EtsActionExtension(runtime); +} + +EtsActionExtension::EtsActionExtension(const std::unique_ptr &runtime) +{ + std::shared_ptr uiExtensionBaseImpl = std::make_shared(runtime); + SetUIExtensionBaseImpl(uiExtensionBaseImpl); +} + +EtsActionExtension::~EtsActionExtension() +{ + TAG_LOGD(AAFwkTag::ACTION_EXT, "destructor"); +} +} // namespace AbilityRuntime +} // namespace OHOS + +ETS_EXPORT extern "C" OHOS::AbilityRuntime::ActionExtension *OHOS_ETS_ACTION_Extension_Create( + const std::unique_ptr &runtime) +{ + return OHOS::AbilityRuntime::EtsActionExtension::Create(runtime); +} \ No newline at end of file diff --git a/frameworks/ets/ani/action_extension_ability/src/ets_action_extension_instance.cpp b/frameworks/ets/ani/action_extension_ability/src/ets_action_extension_instance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b1d7312deaed5992692fb12fbee2d7ef0ca2eff --- /dev/null +++ b/frameworks/ets/ani/action_extension_ability/src/ets_action_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_action_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 = "libaction_extension_ani.z.so"; +const char *ETS_ANI_CREATE_FUNC = "OHOS_ETS_ACTION_Extension_Create"; +using CreateETSActionExtensionFunc = ActionExtension*(*)(const std::unique_ptr&); +CreateETSActionExtensionFunc g_etsCreateFunc = nullptr; +} + +ActionExtension *CreateETSActionExtension(const std::unique_ptr &runtime) +{ + if (g_etsCreateFunc != nullptr) { + return g_etsCreateFunc(runtime); + } + auto handle = dlopen(ETS_ANI_LIBNAME, RTLD_LAZY); + if (handle == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "dlopen failed %{public}s, %{public}s", ETS_ANI_LIBNAME, dlerror()); + return nullptr; + } + auto symbol = dlsym(handle, ETS_ANI_CREATE_FUNC); + if (symbol == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "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/ets/ani/share_extension_ability/BUILD.gn b/frameworks/ets/ani/share_extension_ability/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..59e67679fefa4746c3c7bb339742a1c9cd789a9c --- /dev/null +++ b/frameworks/ets/ani/share_extension_ability/BUILD.gn @@ -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. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("share_extension_ani") { + + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + include_dirs = [ + "./include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/share_extension_ability", + "${ability_runtime_path}/frameworks/ets/ani/ui_extension_base/include", + "${ability_runtime_path}/frameworks/ets/ani/ui_extension_ability/include", + ] + + sources = [ + "${ability_runtime_path}/frameworks/ets/ani/share_extension_ability/src/ets_share_extension.cpp", + ] + + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:share_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", + "${ability_runtime_native_path}/ability/native:ui_extension_ani", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_native_path}/appkit:app_context", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_napi", + "ipc:ipc_single", + "napi:ace_napi", + "runtime_core:ani", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} \ No newline at end of file diff --git a/frameworks/ets/ani/share_extension_ability/include/ets_share_extension.h b/frameworks/ets/ani/share_extension_ability/include/ets_share_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..31a8d3b3176b64ce42b945737a634a3fefaa8396 --- /dev/null +++ b/frameworks/ets/ani/share_extension_ability/include/ets_share_extension.h @@ -0,0 +1,45 @@ +/* + * 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_SHARE_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_ETS_SHARE_EXTENSION_H + +#include "configuration.h" +#include "share_extension.h" +#include "ets_runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +class ShareExtension; +class EtsUIExtensionBase; +/** + * @brief Basic share extension components. + */ +class EtsShareExtension : public ShareExtension, public std::enable_shared_from_this { +public: + explicit EtsShareExtension(const std::unique_ptr &runtime); + virtual ~EtsShareExtension() override; + + /** + * @brief Create EtsShareExtension. + * + * @param runtime The runtime. + * @return The EtsShareExtension instance. + */ + static EtsShareExtension *Create(const std::unique_ptr &runtime); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_SHARE_EXTENSION_H \ No newline at end of file diff --git a/frameworks/ets/ani/share_extension_ability/include/ets_share_extension_instance.h b/frameworks/ets/ani/share_extension_ability/include/ets_share_extension_instance.h new file mode 100644 index 0000000000000000000000000000000000000000..3f4cd627e3e2dd849d615576bc5b3e4bb7ed407d --- /dev/null +++ b/frameworks/ets/ani/share_extension_ability/include/ets_share_extension_instance.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_ETS_SHARE_EXTENSION_INSTANCE_H +#define OHOS_ABILITY_RUNTIME_ETS_SHARE_EXTENSION_INSTANCE_H + +#include "share_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +class ShareExtension; +class Runtime; + +ShareExtension *CreateETSShareExtension(const std::unique_ptr &runtime); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_SHARE_EXTENSION_INSTANCE_H \ No newline at end of file diff --git a/frameworks/ets/ani/share_extension_ability/src/ets_share_extension.cpp b/frameworks/ets/ani/share_extension_ability/src/ets_share_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a72a7339d8fe2f8b2341c56ceda0a76d8a8bd89 --- /dev/null +++ b/frameworks/ets/ani/share_extension_ability/src/ets_share_extension.cpp @@ -0,0 +1,52 @@ +/* + * 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_share_extension.h" + +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" +#include "ets_ui_extension_base.h" + +#ifdef WINDOWS_PLATFORM +#define ETS_EXPORT __declspec(dllexport) +#else +#define ETS_EXPORT __attribute__((visibility("default"))) +#endif + +namespace OHOS { +namespace AbilityRuntime { +EtsShareExtension *EtsShareExtension::Create(const std::unique_ptr &runtime) +{ + return new EtsShareExtension(runtime); +} + +EtsShareExtension::EtsShareExtension(const std::unique_ptr &runtime) +{ + std::shared_ptr uiExtensionBaseImpl = std::make_shared(runtime); + SetUIExtensionBaseImpl(uiExtensionBaseImpl); +} + +EtsShareExtension::~EtsShareExtension() +{ + TAG_LOGD(AAFwkTag::SHARE_EXT, "destructor"); +} +} // namespace AbilityRuntime +} // namespace OHOS + +ETS_EXPORT extern "C" OHOS::AbilityRuntime::ShareExtension *OHOS_ETS_SHARE_Extension_Create( + const std::unique_ptr &runtime) +{ + return OHOS::AbilityRuntime::EtsShareExtension::Create(runtime); +} \ No newline at end of file diff --git a/frameworks/ets/ani/share_extension_ability/src/ets_share_extension_instance.cpp b/frameworks/ets/ani/share_extension_ability/src/ets_share_extension_instance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc78facda7441791a371e5e0403746cee5af3677 --- /dev/null +++ b/frameworks/ets/ani/share_extension_ability/src/ets_share_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_share_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 = "libshare_extension_ani.z.so"; +const char *ETS_ANI_CREATE_FUNC = "OHOS_ETS_SHARE_Extension_Create"; +using CreateETSShareExtensionFunc = ShareExtension*(*)(const std::unique_ptr&); +CreateETSShareExtensionFunc g_etsCreateFunc = nullptr; +} + +ShareExtension *CreateETSShareExtension(const std::unique_ptr &runtime) +{ + if (g_etsCreateFunc != nullptr) { + return g_etsCreateFunc(runtime); + } + auto handle = dlopen(ETS_ANI_LIBNAME, RTLD_LAZY); + if (handle == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "dlopen failed %{public}s, %{public}s", ETS_ANI_LIBNAME, dlerror()); + return nullptr; + } + auto symbol = dlsym(handle, ETS_ANI_CREATE_FUNC); + if (symbol == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "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/ets/ani/ui_extension_base/src/ets_ui_extension_base.cpp b/frameworks/ets/ani/ui_extension_base/src/ets_ui_extension_base.cpp index ef84af974ad6e9aee0fa0bdf9e77808fac4241f1..ff676fdba6b21775adafb7b0ae78798239618007 100644 --- a/frameworks/ets/ani/ui_extension_base/src/ets_ui_extension_base.cpp +++ b/frameworks/ets/ani/ui_extension_base/src/ets_ui_extension_base.cpp @@ -50,6 +50,9 @@ namespace OHOS { namespace AbilityRuntime { namespace { constexpr const char* UIEXTENSION_CLASS_NAME = "L@ohos/app/ability/UIExtensionAbility/UIExtensionAbility;"; +constexpr const char *UIEXT_ONCREATE_SIGNATURE = "C{@ohos.app.ability.AbilityConstant.AbilityConstant.LaunchParam}:"; +constexpr const char *UIEXT_ONSESSIONDESTROY_SIGNATURE = + "C{@ohos.app.ability.UIExtensionContentSession.UIExtensionContentSession}:"; void OnDestroyPromiseCallback(ani_env* env, ani_object aniObj) { @@ -102,6 +105,9 @@ EtsUIExtensionBase::~EtsUIExtensionBase() } } contentSessions_.clear(); + if (shellContextRef_ && shellContextRef_->aniRef) { + env->GlobalReference_Delete(shellContextRef_->aniRef); + } } std::shared_ptr EtsUIExtensionBase::Init(const std::shared_ptr &record, @@ -219,7 +225,8 @@ bool EtsUIExtensionBase::BindNativeMethods() TAG_LOGE(AAFwkTag::UI_EXT, "FindClass failed status: %{public}d", status); return false; } - if ((status = env->Class_BindNativeMethods(cls, functions.data(), functions.size())) != ANI_OK) { + if ((status = env->Class_BindNativeMethods(cls, functions.data(), functions.size())) != ANI_OK + && status != ANI_ALREADY_BINDED) { TAG_LOGE(AAFwkTag::UI_EXT, "Class_BindNativeMethods status: %{public}d", status); return false; } @@ -295,7 +302,7 @@ void EtsUIExtensionBase::OnStart( TAG_LOGE(AAFwkTag::UI_EXT, "null wantObj"); return; } - CallObjectMethod(false, "onCreate", nullptr, launchParamObj, wantObj); + CallObjectMethod(false, "onCreate", UIEXT_ONCREATE_SIGNATURE, launchParamObj, wantObj); } void EtsUIExtensionBase::OnStop() @@ -325,7 +332,7 @@ void EtsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *ca return; } HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::UI_EXT, "begin"); + TAG_LOGD(AAFwkTag::UI_EXT, "OnStop begin"); if (context_) { TAG_LOGD(AAFwkTag::UI_EXT, "set terminating true"); context_->SetTerminating(true); @@ -341,17 +348,14 @@ void EtsUIExtensionBase::OnStop(AppExecFwk::AbilityTransactionCallbackInfo<> *ca callbackInfo->Push(asyncCallback); ani_long destroyCallbackPoint = (ani_long)callbackInfo; ani_status status = ANI_ERROR; - ani_field field = nullptr; auto env = etsRuntime_.GetAniEnv(); if (env == nullptr || etsObj_ == nullptr) { isAsyncCallback = false; OnStop(); return; } - if ((status = env->Class_FindField(etsObj_->aniCls, "destroyCallbackPoint", &field)) != ANI_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); - } - if ((status = env->Object_SetField_Long(etsObj_->aniObj, field, destroyCallbackPoint)) != ANI_OK) { + if ((status = env->Object_SetFieldByName_Long(etsObj_->aniObj, "destroyCallbackPoint", + destroyCallbackPoint)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); } isAsyncCallback = CallObjectMethod(true, "callOnDestroy", ":Z"); @@ -796,7 +800,7 @@ void EtsUIExtensionBase::DestroyWindow(const sptr &sessionIn TAG_LOGE(AAFwkTag::UI_EXT, "contentSessionObj null ptr"); return; } - CallObjectMethod(false, "onSessionDestroy", nullptr, contentSessionObj); + CallObjectMethod(false, "onSessionDestroy", UIEXT_ONSESSIONDESTROY_SIGNATURE, contentSessionObj); } auto &uiWindow = uiWindowMap_[componentId]; if (uiWindow) { @@ -818,20 +822,14 @@ bool EtsUIExtensionBase::CallObjectMethod(bool withResult, const char *name, con TAG_LOGE(AAFwkTag::UI_EXT, "etsObj_ nullptr"); return false; } - auto env = etsRuntime_.GetAniEnv(); ani_status status = ANI_OK; - ani_method method = nullptr; - if ((status = env->Class_FindMethod(etsObj_->aniCls, name, signature, &method)) != ANI_OK) { - TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); - return false; - } env->ResetError(); if (withResult) { ani_boolean res = ANI_FALSE; va_list args; va_start(args, signature); - if ((status = env->Object_CallMethod_Boolean(etsObj_->aniObj, method, &res, args)) != ANI_OK) { + if ((status = env->Object_CallMethodByName_Boolean(etsObj_->aniObj, name, signature, &res, args)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); etsRuntime_.HandleUncaughtError(); } @@ -840,7 +838,7 @@ bool EtsUIExtensionBase::CallObjectMethod(bool withResult, const char *name, con } va_list args; va_start(args, signature); - if ((status = env->Object_CallMethod_Void_V(etsObj_->aniObj, method, args)) != ANI_OK) { + if ((status = env->Object_CallMethodByName_Void_V(etsObj_->aniObj, name, signature, args)) != ANI_OK) { TAG_LOGE(AAFwkTag::UI_EXT, "status: %{public}d", status); etsRuntime_.HandleUncaughtError(); return false; diff --git a/frameworks/ets/ets/@ohos.app.ability.ActionExtensionAbility.ets b/frameworks/ets/ets/@ohos.app.ability.ActionExtensionAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c08375e97296a0f39a64a64420e5c1e520b40d6 --- /dev/null +++ b/frameworks/ets/ets/@ohos.app.ability.ActionExtensionAbility.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; + +export default class ActionExtensionAbility extends UIExtensionAbility { +} \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 6f0d1a22e0a540d61195c81e515734ebd52779c7..9c4cba9a2260a155dc79844a6a27a7107f4e37e3 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -1284,6 +1284,23 @@ ohos_prebuilt_etc("ability_runtime_share_extension_ability_abc_etc") { deps = [ ":ability_runtime_share_extension_ability_abc" ] } +generate_static_abc("ability_runtime_action_extension_ability_abc") { + base_url = "./" + files = [ "./@ohos.app.ability.ActionExtensionAbility.ets" ] + + is_boot_abc = "True" + device_dst_file = + "/system/framework/ability_runtime_action_extension_ability_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_action_extension_ability_abc_etc") { + source = "$target_out_dir/ability_runtime_action_extension_ability_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_action_extension_ability_abc" ] +} + generate_static_abc("ability_runtime_running_multi_instance_info_abc") { base_url = "./" files = [ "./application/RunningMultiInstanceInfo.ets" ] @@ -1307,6 +1324,7 @@ group("ets_packages") { ":ability_runtime_ability_manager_abc_etc", ":ability_delegator_abc_etc", ":ability_delegator_ability_monitor_abc_etc", + ":ability_runtime_action_extension_ability_abc_etc", ":ability_delegator_application_testRunner_abc_etc", ":ability_delegator_args_abc_etc", ":ability_delegator_registry_abc_etc",