diff --git a/bundle.json b/bundle.json index ee446ec9920354c1bef6dc91d74673c0a185664e..425d2e59f63bc84c664c50117f218224647b8065 100644 --- a/bundle.json +++ b/bundle.json @@ -421,6 +421,7 @@ "//foundation/ability/ability_runtime/test/moduletest:moduletest", "//foundation/ability/ability_runtime/test/fuzztest:fuzztest", "//foundation/ability/ability_runtime/test/unittest:unittest", + "//foundation/ability/ability_runtime/test/sample:sample", "//foundation/ability/ability_runtime/tools/test:moduletest", "//foundation/ability/ability_runtime/tools/test:systemtest", "//foundation/ability/ability_runtime/tools/test:unittest", diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index ab9d3a0e187ffbb21c9d29d3d4a9a72bb2b16e79..db777c457aa8f7a288fa3bac436192e614c04bbb 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -1022,7 +1022,15 @@ ohos_shared_library("ui_extension_module") { config("share_extension_config") { visibility = [ ":*" ] - include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/share_extension_ability" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/share_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + ] } ohos_shared_library("share_extension") { @@ -1064,7 +1072,15 @@ ohos_shared_library("share_extension") { config("action_extension_config") { visibility = [ ":*" ] - include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/action_extension_ability" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/action_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + ] } ohos_shared_library("action_extension") { @@ -1126,6 +1142,10 @@ ohos_shared_library("share_extension_module") { "napi:ace_napi", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + relative_install_dir = "extensionability/" subsystem_name = "ability" part_name = "ability_runtime" @@ -1178,6 +1198,10 @@ ohos_shared_library("action_extension_module") { "napi:ace_napi", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + relative_install_dir = "extensionability/" subsystem_name = "ability" part_name = "ability_runtime" @@ -1185,7 +1209,15 @@ ohos_shared_library("action_extension_module") { config("embedded_ui_extension_config") { visibility = [ ":*" ] - include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/embedded_ui_extension_ability" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native/embedded_ui_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + ] } config("embedded_ui_extension_module_config") { @@ -1320,6 +1352,10 @@ ohos_shared_library("embedded_ui_extension_module") { "napi:ace_napi", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + relative_install_dir = "extensionability/" subsystem_name = "ability" part_name = "ability_runtime" diff --git a/frameworks/native/ability/native/action_extension_ability/action_extension.cpp b/frameworks/native/ability/native/action_extension_ability/action_extension.cpp index 2b00ebf74e7250d4ae738acb37e786987bbb80f7..d105b87a619afadf74a6171938108eee2dfa2600 100644 --- a/frameworks/native/ability/native/action_extension_ability/action_extension.cpp +++ b/frameworks/native/ability/native/action_extension_ability/action_extension.cpp @@ -36,13 +36,5 @@ ActionExtension *ActionExtension::Create(const std::unique_ptr &runtime return new ActionExtension(); } } - -void ActionExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - ExtensionBase::Init(record, application, handler, token); -} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp b/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp index 29f5d825380c155b8c4443ba5a22766dc94ed2a2..53e4737f670c72dfea4a22b74b3cc4916ab67512 100644 --- a/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp +++ b/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp @@ -29,150 +29,13 @@ JsActionExtension *JsActionExtension::Create(const std::unique_ptr &run JsActionExtension::JsActionExtension(const std::unique_ptr &runtime) { - jsUIExtensionBase_ = std::make_shared(runtime); + auto uiExtensionBaseImpl = std::make_unique(runtime); + SetUIExtensionBaseImpl(std::move(uiExtensionBaseImpl)); } JsActionExtension::~JsActionExtension() { TAG_LOGD(AAFwkTag::ACTION_EXT, "destructor."); - auto context = GetContext(); - if (context) { - context->Unbind(); - } -} - -void JsActionExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - ActionExtension::Init(record, application, handler, token); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->SetAbilityInfo(abilityInfo_); - jsUIExtensionBase_->SetContext(GetContext()); - auto extensionCommon = jsUIExtensionBase_->Init(record, application, handler, token); - SetExtensionCommon(extensionCommon); -} - -void JsActionExtension::OnStart(const AAFwk::Want &want) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - Extension::OnStart(want); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStart(want); -} - -void JsActionExtension::OnStop() -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - ActionExtension::OnStop(); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStop(); -} - -void JsActionExtension::OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "begin. persistentId: %{private}d, winCmd: %{public}d", - sessionInfo->persistentId, winCmd); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "sessionInfo is nullptr."); - return; - } - Extension::OnCommandWindow(want, sessionInfo, winCmd); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommandWindow(want, sessionInfo, winCmd); -} - -void JsActionExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) -{ - Extension::OnCommand(want, restart, startId); - TAG_LOGD(AAFwkTag::ACTION_EXT, "begin restart = %{public}s, startId = %{public}d.", - restart ? "true" : "false", startId); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommand(want, restart, startId); -} - -void JsActionExtension::OnForeground(const Want &want, sptr sessionInfo) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - Extension::OnForeground(want, sessionInfo); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnForeground(want, sessionInfo); -} - -void JsActionExtension::OnBackground() -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnBackground(); - Extension::OnBackground(); -} - -void JsActionExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - Extension::OnConfigurationUpdated(configuration); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnConfigurationUpdated(configuration); -} - -void JsActionExtension::Dump(const std::vector ¶ms, std::vector &info) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "called."); - Extension::Dump(params, info); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->Dump(params, info); -} - -void JsActionExtension::OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) -{ - TAG_LOGD(AAFwkTag::ACTION_EXT, "OnAbilityResult called."); - Extension::OnAbilityResult(requestCode, resultCode, resultData); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::ACTION_EXT, "jsUIExtensionBase_ is null"); - return; - } - jsUIExtensionBase_->OnAbilityResult(requestCode, resultCode, resultData); } } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.cpp b/frameworks/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.cpp index d705ab0026c2c0f20ae326058bddbd4d6b45813a..c6d3beed6769dcb45fae4277c527f58b3bcdccd4 100644 --- a/frameworks/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.cpp +++ b/frameworks/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.cpp @@ -36,13 +36,5 @@ EmbeddedUIExtension *EmbeddedUIExtension::Create(const std::unique_ptr return new (std::nothrow) EmbeddedUIExtension(); } } - -void EmbeddedUIExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - ExtensionBase::Init(record, application, handler, token); -} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.cpp b/frameworks/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.cpp index 182dd7c1a6b611dd10ebd7dfc323a4d476c77aa3..af039f94cd520427c0f0643d71b8a5f0828351a9 100644 --- a/frameworks/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.cpp +++ b/frameworks/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.cpp @@ -29,150 +29,13 @@ JsEmbeddedUIExtension *JsEmbeddedUIExtension::Create(const std::unique_ptr &runtime) { - jsUIExtensionBase_ = std::make_shared(runtime); + auto uiExtensionBaseImpl = std::make_unique(runtime); + SetUIExtensionBaseImpl(std::move(uiExtensionBaseImpl)); } JsEmbeddedUIExtension::~JsEmbeddedUIExtension() { TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "destructor."); - auto context = GetContext(); - if (context) { - context->Unbind(); - } -} - -void JsEmbeddedUIExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - EmbeddedUIExtension::Init(record, application, handler, token); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->SetAbilityInfo(abilityInfo_); - jsUIExtensionBase_->SetContext(GetContext()); - auto extensionCommon = jsUIExtensionBase_->Init(record, application, handler, token); - SetExtensionCommon(extensionCommon); -} - -void JsEmbeddedUIExtension::OnStart(const AAFwk::Want &want) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - Extension::OnStart(want); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStart(want); -} - -void JsEmbeddedUIExtension::OnStop() -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - EmbeddedUIExtension::OnStop(); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStop(); -} - -void JsEmbeddedUIExtension::OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "begin. persistentId: %{private}d, winCmd: %{public}d", - sessionInfo->persistentId, winCmd); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "sessionInfo is nullptr."); - return; - } - Extension::OnCommandWindow(want, sessionInfo, winCmd); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommandWindow(want, sessionInfo, winCmd); -} - -void JsEmbeddedUIExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) -{ - Extension::OnCommand(want, restart, startId); - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "begin restart = %{public}s, startId = %{public}d.", - restart ? "true" : "false", startId); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommand(want, restart, startId); -} - -void JsEmbeddedUIExtension::OnForeground(const Want &want, sptr sessionInfo) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - Extension::OnForeground(want, sessionInfo); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnForeground(want, sessionInfo); -} - -void JsEmbeddedUIExtension::OnBackground() -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnBackground(); - Extension::OnBackground(); -} - -void JsEmbeddedUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - Extension::OnConfigurationUpdated(configuration); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnConfigurationUpdated(configuration); -} - -void JsEmbeddedUIExtension::Dump(const std::vector ¶ms, std::vector &info) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "called."); - Extension::Dump(params, info); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->Dump(params, info); -} - -void JsEmbeddedUIExtension::OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) -{ - TAG_LOGD(AAFwkTag::EMBEDDED_EXT, "OnAbilityResult called."); - Extension::OnAbilityResult(requestCode, resultCode, resultData); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::EMBEDDED_EXT, "jsUIExtensionBase_ is null"); - return; - } - jsUIExtensionBase_->OnAbilityResult(requestCode, resultCode, resultData); } } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp b/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp index b556d204d06413a9f4b39a503de408c7315866cc..a3d0689078ce80cf8f6ce59d6a45eff69e2559a4 100644 --- a/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp +++ b/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp @@ -29,149 +29,13 @@ JsShareExtension *JsShareExtension::Create(const std::unique_ptr &runti JsShareExtension::JsShareExtension(const std::unique_ptr &runtime) { - jsUIExtensionBase_ = std::make_shared(runtime); + auto uiExtensionBaseImpl = std::make_unique(runtime); + SetUIExtensionBaseImpl(std::move(uiExtensionBaseImpl)); } JsShareExtension::~JsShareExtension() { TAG_LOGD(AAFwkTag::SHARE_EXT, "destructor."); - auto context = GetContext(); - if (context) { - context->Unbind(); - } -} - -void JsShareExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - ShareExtension::Init(record, application, handler, token); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->SetAbilityInfo(abilityInfo_); - jsUIExtensionBase_->SetContext(GetContext()); - auto extensionCommon = jsUIExtensionBase_->Init(record, application, handler, token); - SetExtensionCommon(extensionCommon); -} - -void JsShareExtension::OnStart(const AAFwk::Want &want) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - Extension::OnStart(want); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStart(want); -} - -void JsShareExtension::OnStop() -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - ShareExtension::OnStop(); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnStop(); -} - -void JsShareExtension::OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "begin. persistentId: %{private}d, winCmd: %{public}d", - sessionInfo->persistentId, winCmd); - if (sessionInfo == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "sessionInfo is nullptr."); - return; - } - Extension::OnCommandWindow(want, sessionInfo, winCmd); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommandWindow(want, sessionInfo, winCmd); -} - -void JsShareExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) -{ - Extension::OnCommand(want, restart, startId); - TAG_LOGD(AAFwkTag::SHARE_EXT, "begin restart = %{public}s, startId = %{public}d.", - restart ? "true" : "false", startId); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnCommand(want, restart, startId); -} - -void JsShareExtension::OnForeground(const Want &want, sptr sessionInfo) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - Extension::OnForeground(want, sessionInfo); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnForeground(want, sessionInfo); -} - -void JsShareExtension::OnBackground() -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "OnBackground called."); - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr."); - return; - } - jsUIExtensionBase_->OnBackground(); - Extension::OnBackground(); -} - -void JsShareExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - Extension::OnConfigurationUpdated(configuration); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnConfigurationUpdated(configuration); -} - -void JsShareExtension::Dump(const std::vector ¶ms, std::vector &info) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - Extension::Dump(params, info); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->Dump(params, info); -} - -void JsShareExtension::OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - Extension::OnAbilityResult(requestCode, resultCode, resultData); - - if (jsUIExtensionBase_ == nullptr) { - TAG_LOGE(AAFwkTag::SHARE_EXT, "jsUIExtensionBase_ is nullptr"); - return; - } - jsUIExtensionBase_->OnAbilityResult(requestCode, resultCode, resultData); } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/share_extension_ability/share_extension.cpp b/frameworks/native/ability/native/share_extension_ability/share_extension.cpp index a3198ca12eb1634e5f70755a11f9f203c15df43a..eaf583ff374ddfa088e43ade2bb7f7604bf9b599 100644 --- a/frameworks/native/ability/native/share_extension_ability/share_extension.cpp +++ b/frameworks/native/ability/native/share_extension_ability/share_extension.cpp @@ -36,13 +36,5 @@ ShareExtension *ShareExtension::Create(const std::unique_ptr &runtime) return new ShareExtension(); } } - -void ShareExtension::Init(const std::shared_ptr &record, - const std::shared_ptr &application, std::shared_ptr &handler, - const sptr &token) -{ - TAG_LOGD(AAFwkTag::SHARE_EXT, "called."); - ExtensionBase::Init(record, application, handler, token); -} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index e3bce4f6b9a70b39c5084a1e17f880c832698be3..314d9612c79c357a82fa4cd5385c1ba0b4393cbc 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -114,7 +114,7 @@ JsUIExtensionBase::~JsUIExtensionBase() contentSessions_.clear(); } -std::shared_ptr JsUIExtensionBase::Init(const std::shared_ptr &record, +std::shared_ptr JsUIExtensionBase::Init(const std::shared_ptr &record, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) { diff --git a/interfaces/kits/native/ability/native/action_extension_ability/action_extension.h b/interfaces/kits/native/ability/native/action_extension_ability/action_extension.h index 63c404ba9725ee781323405506cc0d12a2280335..4d2232aed8b42f63ddfc3bfb2835897cbcb8c3a7 100644 --- a/interfaces/kits/native/ability/native/action_extension_ability/action_extension.h +++ b/interfaces/kits/native/ability/native/action_extension_ability/action_extension.h @@ -16,7 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_ACTION_EXTENSION_H #define OHOS_ABILITY_RUNTIME_ACTION_EXTENSION_H -#include "extension_base.h" +#include "ui_extension_base.h" namespace OHOS { namespace AbilityRuntime { @@ -25,22 +25,12 @@ class Runtime; /** * @brief Action extension components. */ -class ActionExtension : public ExtensionBase, public std::enable_shared_from_this { +class ActionExtension : public UIExtensionBase, + public std::enable_shared_from_this { public: ActionExtension() = default; virtual ~ActionExtension() = default; - /** - * @brief Init the action extension. - * - * @param record the action extension record. - * @param application the application info. - * @param handler the action 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 action extension. * diff --git a/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h b/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h index 53214c0f050037dbff3357976460263ce319c17b..334d8997350f72c0093f618f0535d9275d0b3e80 100644 --- a/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h +++ b/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h @@ -39,102 +39,6 @@ public: * @return The JsActionExtension instance. */ static JsActionExtension *Create(const std::unique_ptr &runtime); - - /** - * @brief Init the action extension. - * - * @param record the action extension record. - * @param application the application info. - * @param handler the action 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 Called when this action extension is started. You must override this function if you want to perform some - * initialization operations during action extension startup. - * - * This function can be called only once in the entire lifecycle of an action extension. - * - * @param Want Indicates the {@link Want} structure containing startup information about the action extension. - */ - void OnStart(const AAFwk::Want &want) override; - - /** - * @brief Called back when action extension is started. - * - * This method can be called only by action extension. You can use the StartAbility(Want) method to start - * action extension. 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 action extension to start. - * @param restart Indicates the startup mode. The value true indicates that action extension is restarted after - * being destroyed, and the value false indicates a normal startup. - * @param startId Indicates the number of times the action extension has been started. The startId is incremented - * by 1 every time the action extension is started. For example, if the action extension has been started for six - * times, the value of startId is 6. - */ - void OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) override; - - void OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; - - /** - * @brief Called when this action extension enters the STATE_STOP state. - * - * The action extension in the STATE_STOP is being destroyed. - * You can override this function to implement your own processing logic. - */ - 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 this extension enters the STATE_FOREGROUND state. - * - * - * The extension in the STATE_FOREGROUND state is visible. - * You can override this function to implement your own processing logic. - */ - void OnForeground(const Want &want, sptr sessionInfo) override; - - /** - * @brief Called when this extension enters the STATE_BACKGROUND state. - * - * - * The extension in the STATE_BACKGROUND state is invisible. - * You can override this function to implement your own processing logic. - */ - void OnBackground() override; - - /** - * @brief Called when action extension need dump info. - * - * @param params The params from action extension. - * @param info The dump info to show. - */ - void Dump(const std::vector ¶ms, std::vector &info) override; - - /** - * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int32_t) is called to start an extension ability - * and the result is returned. - * @param requestCode Indicates the request code returned after the ability is started. You can define the request - * code to identify the results returned by abilities. The value ranges from 0 to 65535. - * @param resultCode Indicates the result code returned after the ability is started. You can define the result - * code to identify an error. - * @param resultData Indicates the data returned after the ability is started. You can define the data returned. The - * value can be null. - */ - void OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) override; -private: - std::shared_ptr jsUIExtensionBase_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.h b/interfaces/kits/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.h index dd4145323e06e3a798ed4d9f52d54b85d016e5b5..d24ef1f34c0a58935b3e51d189f7cb933b8ea113 100644 --- a/interfaces/kits/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.h +++ b/interfaces/kits/native/ability/native/embedded_ui_extension_ability/embedded_ui_extension.h @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_ACTION_EXTENSION_H -#define OHOS_ABILITY_RUNTIME_ACTION_EXTENSION_H +#ifndef OHOS_ABILITY_RUNTIME_EMBEDDED_UI_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_EMBEDDED_UI_EXTENSION_H -#include "extension_base.h" +#include "ui_extension_base.h" namespace OHOS { namespace AbilityRuntime { @@ -26,23 +26,12 @@ class Runtime; * @brief embedded UI extension components. */ class EmbeddedUIExtension - : public ExtensionBase, public std::enable_shared_from_this { + : public UIExtensionBase, public std::enable_shared_from_this { public: EmbeddedUIExtension() = default; ~EmbeddedUIExtension() override = default; - /** - * @brief Init the embedded UI extension. - * - * @param record the embedded UI extension record. - * @param application the application info. - * @param handler the embedded UI 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 embedded UI extension. * @@ -53,4 +42,4 @@ public: }; } // namespace AbilityRuntime } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_ACTION_EXTENSION_H +#endif // OHOS_ABILITY_RUNTIME_EMBEDDED_UI_EXTENSION_H diff --git a/interfaces/kits/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.h b/interfaces/kits/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.h index 653f194b59f0e0c1e8f66976dfe7eb9529fcc270..862b7edf9d8253ab5376831f04e6d8692fe59f4a 100644 --- a/interfaces/kits/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.h +++ b/interfaces/kits/native/ability/native/embedded_ui_extension_ability/js_embedded_ui_extension.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_JS_ACTION_EXTENSION_H -#define OHOS_ABILITY_RUNTIME_JS_ACTION_EXTENSION_H +#ifndef OHOS_ABILITY_RUNTIME_JS_EMBEDDED_UI_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_JS_EMBEDDED_UI_EXTENSION_H #include "embedded_ui_extension.h" #include "configuration.h" @@ -39,103 +39,7 @@ public: * @return The JsEmbeddedUIExtension instance. */ static JsEmbeddedUIExtension *Create(const std::unique_ptr &runtime); - - /** - * @brief Init the embedded UI extension. - * - * @param record the embedded UI extension record. - * @param application the application info. - * @param handler the embedded UI 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 Called when this embedded UI extension is started. You must override this function if you want to perform - * some initialization operations during embedded UI extension startup. - * - * This function can be called only once in the entire lifecycle of an embedded UI extension. - * - * @param Want Indicates the {@link Want} structure containing startup information about the embedded UI extension. - */ - void OnStart(const AAFwk::Want &want) override; - - /** - * @brief Called back when embedded UI extension is started. - * - * This method can be called only by embedded UI extension. You can use the StartAbility(Want) method to start - * embedded UI extension. 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 embedded UI extension to start. - * @param restart Indicates the startup mode. The value true indicates that embedded UI extension is restarted after - * being destroyed, and the value false indicates a normal startup. - * @param startId Indicates the number of times the embedded UI extension has been started. - * The startId is incremented by 1 every time the embedded UI extension is started. For example, - * if the embedded UI extension has been started for six times, the value of startId is 6. - */ - void OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) override; - - void OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; - - /** - * @brief Called when this embedded UI extension enters the STATE_STOP state. - * - * The embedded UI extension in the STATE_STOP is being destroyed. - * You can override this function to implement your own processing logic. - */ - 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 this extension enters the STATE_FOREGROUND state. - * - * - * The extension in the STATE_FOREGROUND state is visible. - * You can override this function to implement your own processing logic. - */ - void OnForeground(const Want &want, sptr sessionInfo) override; - - /** - * @brief Called when this extension enters the STATE_BACKGROUND state. - * - * - * The extension in the STATE_BACKGROUND state is invisible. - * You can override this function to implement your own processing logic. - */ - void OnBackground() override; - - /** - * @brief Called when embedded UI extension need dump info. - * - * @param params The params from embedded UI extension. - * @param info The dump info to show. - */ - void Dump(const std::vector ¶ms, std::vector &info) override; - - /** - * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int32_t) is called to start an extension ability - * and the result is returned. - * @param requestCode Indicates the request code returned after the ability is started. You can define the request - * code to identify the results returned by abilities. The value ranges from 0 to 65535. - * @param resultCode Indicates the result code returned after the ability is started. You can define the result - * code to identify an error. - * @param resultData Indicates the data returned after the ability is started. You can define the data returned. The - * value can be null. - */ - void OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) override; -private: - std::shared_ptr jsUIExtensionBase_; }; } // namespace AbilityRuntime } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_JS_ACTION_EXTENSION_H +#endif // OHOS_ABILITY_RUNTIME_JS_EMBEDDED_UI_EXTENSION_H diff --git a/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h b/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h index ddbbd15aa4ab934890b7e4d200dc1b16e23d597f..e03e2409216f51a616ce54e00d0bcd2517d84372 100644 --- a/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h +++ b/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h @@ -41,103 +41,6 @@ public: * @return The JsShareExtension instance. */ static JsShareExtension *Create(const std::unique_ptr &runtime); - - /** - * @brief Init the share extension. - * - * @param record the share extension record. - * @param application the application info. - * @param handler the share 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 Called when this share extension is started. You must override this function if you want to perform some - * initialization operations during share extension startup. - * - * This function can be called only once in the entire lifecycle of an share extension. - * - * @param Want Indicates the {@link Want} structure containing startup information about the share extension. - */ - void OnStart(const AAFwk::Want &want) override; - - /** - * @brief Called back when share extension is started. - * - * This method can be called only by share extension. You can use the StartAbility(Want) method to start - * share extension. 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 share extension to start. - * @param restart Indicates the startup mode. The value true indicates that share extension is restarted after being - * destroyed, and the value false indicates a normal startup. - * @param startId Indicates the number of times the share extension has been started. The startId is incremented - * by 1 every time the share extension is started. For example, if the share extension has been started for six - * times, the value of startId is 6. - */ - void OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) override; - - void OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; - - /** - * @brief Called when this share extension enters the STATE_STOP state. - * - * The share extension in the STATE_STOP is being destroyed. - * You can override this function to implement your own processing logic. - */ - 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 this extension enters the STATE_FOREGROUND state. - * - * - * The extension in the STATE_FOREGROUND state is visible. - * You can override this function to implement your own processing logic. - */ - void OnForeground(const Want &want, sptr sessionInfo) override; - - /** - * @brief Called when this extension enters the STATE_BACKGROUND state. - * - * - * The extension in the STATE_BACKGROUND state is invisible. - * You can override this function to implement your own processing logic. - */ - void OnBackground() override; - - /** - * @brief Called when share extension need dump info. - * - * @param params The params from share extension. - * @param info The dump info to show. - */ - void Dump(const std::vector ¶ms, std::vector &info) override; - - /** - * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int32_t) is called to start an extension ability - * and the result is returned. - * @param requestCode Indicates the request code returned after the ability is started. You can define the request - * code to identify the results returned by abilities. The value ranges from 0 to 65535. - * @param resultCode Indicates the result code returned after the ability is started. You can define the result - * code to identify an error. - * @param resultData Indicates the data returned after the ability is started. You can define the data returned. The - * value can be null. - */ - void OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) override; - -private: - std::shared_ptr jsUIExtensionBase_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/share_extension_ability/share_extension.h b/interfaces/kits/native/ability/native/share_extension_ability/share_extension.h index 132cf0e72e4ca1c83e18b23b09ccf394a0e0513b..b10f6af5b759d94ae53fd048889736fc92393fc0 100644 --- a/interfaces/kits/native/ability/native/share_extension_ability/share_extension.h +++ b/interfaces/kits/native/ability/native/share_extension_ability/share_extension.h @@ -16,7 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_SHARE_EXTENSION_H #define OHOS_ABILITY_RUNTIME_SHARE_EXTENSION_H -#include "extension_base.h" +#include "ui_extension_base.h" namespace OHOS { namespace AbilityRuntime { @@ -25,22 +25,12 @@ class Runtime; /** * @brief Share extension components. */ -class ShareExtension : public ExtensionBase, public std::enable_shared_from_this { +class ShareExtension : public UIExtensionBase, + public std::enable_shared_from_this { public: ShareExtension() = default; virtual ~ShareExtension() = default; - /** - * @brief Init the share extension. - * - * @param record the share extension record. - * @param application the application info. - * @param handler the share 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 share extension. * diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h index a85207dbbd10235cba17889d839e95133c804f54..a148ed9810c9c29e28dfe5f78b2cfd9c64a86b8d 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h @@ -24,6 +24,7 @@ #include "native_engine/native_engine.h" #include "ohos_application.h" #include "session_info.h" +#include "ui_extension_base.h" #include "ui_extension_context.h" #include "ui_extension_window_command.h" #include "want.h" @@ -38,7 +39,8 @@ class JsRuntime; /** * @brief Js ui extension base. */ -class JsUIExtensionBase : public std::enable_shared_from_this { +class JsUIExtensionBase : public UIExtensionBaseImpl, + public std::enable_shared_from_this { public: explicit JsUIExtensionBase(const std::unique_ptr &runtime); virtual ~JsUIExtensionBase(); @@ -52,9 +54,9 @@ public: * @param token the remote token. * @return js extension common object. */ - std::shared_ptr Init(const std::shared_ptr &record, + std::shared_ptr Init(const std::shared_ptr &record, const std::shared_ptr &application, - std::shared_ptr &handler, const sptr &token); + std::shared_ptr &handler, const sptr &token) override; /** * @brief Called when this ui extension is started. You must override this function if you want to perform some @@ -64,7 +66,7 @@ public: * * @param Want Indicates the {@link Want} structure containing startup information about the ui extension. */ - void OnStart(const AAFwk::Want &want); + void OnStart(const AAFwk::Want &want) override; /** * @brief Called back when ui extension is started. @@ -80,10 +82,10 @@ public: * by 1 every time the ui extension is started. For example, if the ui extension has been started for six * times, the value of startId is 6. */ - void OnCommand(const AAFwk::Want &want, bool restart, int32_t startId); + void OnCommand(const AAFwk::Want &want, bool restart, int32_t startId) override; void OnCommandWindow( - const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd); + const AAFwk::Want &want, const sptr &sessionInfo, AAFwk::WindowCommand winCmd) override; /** * @brief Called when this ui extension enters the STATE_STOP state. @@ -91,14 +93,14 @@ public: * The ui extension in the STATE_STOP is being destroyed. * You can override this function to implement your own processing logic. */ - void OnStop(); + void OnStop() override; /** * @brief Called when the system configuration is updated. * * @param configuration Indicates the updated configuration information. */ - void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration); + void OnConfigurationUpdated(const AppExecFwk::Configuration &configuration) override; /** * @brief Called when this extension enters the STATE_FOREGROUND state. @@ -107,7 +109,7 @@ public: * The extension in the STATE_FOREGROUND state is visible. * You can override this function to implement your own processing logic. */ - void OnForeground(const Want &want, sptr sessionInfo); + void OnForeground(const Want &want, sptr sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. @@ -116,7 +118,7 @@ public: * The extension in the STATE_BACKGROUND state is invisible. * You can override this function to implement your own processing logic. */ - void OnBackground(); + void OnBackground() override; /** * @brief Called when ui extension need dump info. @@ -124,7 +126,7 @@ public: * @param params The params from ui extension. * @param info The dump info to show. */ - void Dump(const std::vector ¶ms, std::vector &info); + void Dump(const std::vector ¶ms, std::vector &info) override; /** * @brief Called when startAbilityForResult(ohos.aafwk.content.Want,int32_t) is called to start an extension ability @@ -136,17 +138,17 @@ public: * @param resultData Indicates the data returned after the ability is started. You can define the data returned. The * value can be null. */ - void OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData); + void OnAbilityResult(int32_t requestCode, int32_t resultCode, const Want &resultData) override; /** * @brief Set ability info. */ - void SetAbilityInfo(const std::shared_ptr &abilityInfo); + void SetAbilityInfo(const std::shared_ptr &abilityInfo) override; /** * @brief Set ui extension context. */ - void SetContext(const std::shared_ptr &context); + void SetContext(const std::shared_ptr &context) override; private: void BindContext(napi_env env, napi_value obj); diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h new file mode 100644 index 0000000000000000000000000000000000000000..b26b5a6681ffa7b048eee8f3b970cd592b8a9ee1 --- /dev/null +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2024 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_UI_EXTENSION_BASE_H +#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_BASE_H + +#include + +#include "extension.h" +#include "extension_base.h" +#include "iremote_object.h" +#include "ui_extension_context.h" +#include "ui_extension_base_impl.h" + +namespace OHOS { +namespace AbilityRuntime { +template +class UIExtensionBase : public ExtensionBase { +public: + UIExtensionBase() = default; + virtual ~UIExtensionBase() + { + auto context = ExtensionBase::GetContext(); + if (context != nullptr) { + context->Unbind(); + } + } + + void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override + { + ExtensionBase::Init(record, application, handler, token); + if (impl_ != nullptr) { + impl_->SetAbilityInfo(Extension::abilityInfo_); + impl_->SetContext(ExtensionBase::GetContext()); + auto extensionCommon = impl_->Init(record, application, handler, token); + ExtensionBase::SetExtensionCommon(extensionCommon); + } + } + + void OnStart(const AAFwk::Want &want) override + { + Extension::OnStart(want); + if (impl_ != nullptr) { + impl_->OnStart(want); + } + } + + void OnCommand(const AAFwk::Want &want, bool restart, int startId) override + { + Extension::OnCommand(want, restart, startId); + if (impl_ != nullptr) { + impl_->OnCommand(want, restart, startId); + } + } + + void OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, + AAFwk::WindowCommand winCmd) override + { + Extension::OnCommandWindow(want, sessionInfo, winCmd); + if (impl_ != nullptr) { + impl_->OnCommandWindow(want, sessionInfo, winCmd); + } + } + + void OnStop() override + { + Extension::OnStop(); + if (impl_ != nullptr) { + impl_->OnStop(); + } + } + + void OnForeground(const Want &want, sptr sessionInfo) override + { + Extension::OnForeground(want, sessionInfo); + if (impl_ != nullptr) { + impl_->OnForeground(want, sessionInfo); + } + } + + void OnBackground() override + { + if (impl_ != nullptr) { + impl_->OnBackground(); + } + Extension::OnBackground(); + } + + void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override + { + Extension::OnConfigurationUpdated(configuration); + if (impl_ != nullptr) { + impl_->OnConfigurationUpdated(configuration); + } + } + + void Dump(const std::vector ¶ms, std::vector &info) override + { + Extension::Dump(params, info); + if (impl_ != nullptr) { + impl_->Dump(params, info); + } + } + + void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override + { + Extension::OnAbilityResult(requestCode, resultCode, resultData); + if (impl_ != nullptr) { + impl_->OnAbilityResult(requestCode, resultCode, resultData); + } + } + + void SetUIExtensionBaseImpl(std::unique_ptr impl) + { + impl_ = std::move(impl); + } + +private: + std::unique_ptr impl_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_BASE_H diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..7bfbc8df52dd64fe2f3dc809b90ae9069dc9cbf3 --- /dev/null +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_base_impl.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 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_UI_EXTENSION_BASE_IMPL_H +#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_BASE_IMPL_H + +#include + +#include "extension_common.h" +#include "iremote_object.h" +#include "ui_extension_context.h" +#include "ui_extension_base_impl.h" + +namespace OHOS { +namespace AbilityRuntime { +class UIExtensionBaseImpl { +public: + UIExtensionBaseImpl() = default; + virtual ~UIExtensionBaseImpl() = default; + + virtual std::shared_ptr Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) = 0; + + virtual void OnStart(const AAFwk::Want &want) = 0; + + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) = 0; + + virtual void OnCommandWindow(const AAFwk::Want &want, const sptr &sessionInfo, + AAFwk::WindowCommand winCmd) = 0; + + virtual void OnStop() = 0; + + virtual void OnForeground(const Want &want, sptr sessionInfo) = 0; + + virtual void OnBackground() = 0; + + virtual void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) = 0; + + virtual void Dump(const std::vector ¶ms, std::vector &info) = 0; + + virtual void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) = 0; + + virtual void SetAbilityInfo(const std::shared_ptr &abilityInfo) = 0; + + virtual void SetContext(const std::shared_ptr &context) = 0; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_BASE_IMPL_H diff --git a/test/sample/BUILD.gn b/test/sample/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..220fe2bbfc2583522cf679864eaead85f7309969 --- /dev/null +++ b/test/sample/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2024 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("//foundation/ability/ability_runtime/ability_runtime.gni") + +group("sample") { + testonly = true + + deps = [ "demo_ui_extension:ui_extension_sample" ] +} diff --git a/test/sample/demo_ui_extension/BUILD.gn b/test/sample/demo_ui_extension/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0689d4dcbb06ee318cc225bd7fc2f8d3e2c21ca7 --- /dev/null +++ b/test/sample/demo_ui_extension/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2024 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("//foundation/ability/ability_runtime/ability_runtime.gni") + +group("ui_extension_sample") { + deps = [ + "js/napi/demo_ui_extension_ability:demouiextensionability_napi", + + # Compiling below so to a same so is also fine. + "native/demo_ui_extension_ability:demo_ui_extension", + "native/demo_ui_extension_ability:demo_ui_extension_module", + ] +} diff --git a/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/BUILD.gn b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b47cd7e6683b5831a453a76634e5922039ec2235 --- /dev/null +++ b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/BUILD.gn @@ -0,0 +1,60 @@ +# Copyright (c) 2024 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//build/ohos.gni") + +es2abc_gen_abc("gen_demo_ui_extension_ability_abc") { + src_js = rebase_path("demo_ui_extension_ability.js") + dst_file = rebase_path(target_out_dir + "/demo_ui_extension_ability.abc") + in_puts = [ "demo_ui_extension_ability.js" ] + out_puts = [ target_out_dir + "/demo_ui_extension_ability.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("demo_ui_extension_ability_js") { + input = "demo_ui_extension_ability.js" + output = target_out_dir + "/demo_ui_extension_ability.o" +} + +gen_js_obj("demo_ui_extension_ability_abc") { + input = get_label_info(":gen_demo_ui_extension_ability_abc", + "target_out_dir") + "/demo_ui_extension_ability.abc" + output = target_out_dir + "/demo_ui_extension_ability_abc.o" + dep = ":gen_demo_ui_extension_ability_abc" +} + +ohos_shared_library("demouiextensionability_napi") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = [ "demo_ui_extension_ability_module.cpp" ] + + deps = [ + ":demo_ui_extension_ability_abc", + ":demo_ui_extension_ability_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/app/ability" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability.js b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability.js new file mode 100644 index 0000000000000000000000000000000000000000..04bccd8ed5671b74be1508a1aad02fa84b4437c0 --- /dev/null +++ b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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. + */ + +let UIExtensionAbility = requireNapi('app.ability.UIExtensionAbility'); + +class DemoUIExtensionAbility extends UIExtensionAbility { +} + +export default DemoUIExtensionAbility; diff --git a/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability_module.cpp b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0224222abb8d34acbc1ea4488a9914f1ab24a71 --- /dev/null +++ b/test/sample/demo_ui_extension/js/napi/demo_ui_extension_ability/demo_ui_extension_ability_module.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 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 "native_engine/native_engine.h" + +extern const char _binary_demo_ui_extension_ability_js_start[]; +extern const char _binary_demo_ui_extension_ability_js_end[]; +extern const char _binary_demo_ui_extension_ability_abc_start[]; +extern const char _binary_demo_ui_extension_ability_abc_end[]; + +static napi_module demo_ui_extension_ability_module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = "app/ability/libdemouiextensionability_napi.so/demo_ui_extension_ability.js", + .nm_register_func = nullptr, + // Attension: the name should consistent with the DemoUIExtensionAbility.d.ts path + .nm_modname = "app.ability.DemoUIExtensionAbility", + .nm_priv = ((void *)0), + .reserved = {0} +}; + +extern "C" __attribute__((constructor)) +void NAPI_app_ability_DemoUIExtensionAbility_AutoRegister() +{ + napi_module_register(&demo_ui_extension_ability_module); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_app_ability_DemoUIExtensionAbility_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_demo_ui_extension_ability_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_demo_ui_extension_ability_js_end - _binary_demo_ui_extension_ability_js_start; + } +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_app_ability_DemoUIExtensionAbility_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_demo_ui_extension_ability_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_demo_ui_extension_ability_abc_end - _binary_demo_ui_extension_ability_abc_start; + } +} diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/BUILD.gn b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3db9b188e273a174e2d60b59deaefaf912ea30fa --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/BUILD.gn @@ -0,0 +1,119 @@ +# Copyright (c) 2024 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/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +config("demo_ui_extension_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", + ] +} + +ohos_shared_library("demo_ui_extension") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + configs = [ ":demo_ui_extension_config" ] + + sources = [ + "src/demo_ui_extension.cpp", + "src/js_demo_ui_extension.cpp", + ] + + # If not in ability_runtime repo, use external_deps + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:ui_extension", + "${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", + "napi:ace_napi", + ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + + subsystem_name = "ability" + part_name = "ability_runtime" +} + +config("demo_ui_extension_module_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + ] +} + +ohos_shared_library("demo_ui_extension_module") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + sources = [ "src/demo_ui_extension_module_loader.cpp" ] + + configs = [ + ":demo_ui_extension_module_config", + ":demo_ui_extension_config", + ] + + deps = [ + ":demo_ui_extension", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/ability/native:extensionkit_native", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "bundle_framework:appexecfwk_core", + "hilog:libhilog", + "napi:ace_napi", + ] + + relative_install_dir = "extensionability/" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension.h b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..86ed6700ac2c948ebcfb87eae7554d59828c06bf --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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_DEMO_UI_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_DEMO_UI_EXTENSION_H + +#include "runtime.h" +#include "ui_extension_base.h" +#include "ui_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +class DemoUIExtension : public UIExtensionBase, + public std::enable_shared_from_this { +public: + DemoUIExtension() = default; + ~DemoUIExtension() override = default; + + /** + * @brief Create demo UI extension. + * + * @param runtime The runtime. + * @return The demo UI extension instance. + */ + static DemoUIExtension *Create(const std::unique_ptr &runtime); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DEMO_UI_EXTENSION_H diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension_module_loader.h b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension_module_loader.h new file mode 100644 index 0000000000000000000000000000000000000000..e91f40523855a8f3a9e43cad7f3ea5d496279300 --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/demo_ui_extension_module_loader.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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_DEMO_UI_EXTENSION_MODULE_LOADER_H +#define OHOS_ABILITY_RUNTIME_DEMO_UI_EXTENSION_MODULE_LOADER_H + +#include "extension_module_loader.h" +#include "runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +class DemoUIExtensionModuleLoader : public ExtensionModuleLoader, + public Singleton { + DECLARE_SINGLETON(DemoUIExtensionModuleLoader); + +public: + /** + * @brief Create Extension. + * + * @param runtime The runtime. + * @return The Extension instance. + */ + Extension *Create(const std::unique_ptr &runtime) const override; + + /** + * @brief Get the Params object + * + * @return std::map The map of extension type and extension name. + */ + std::map GetParams() override; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DEMO_UI_EXTENSION_MODULE_LOADER_H diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/js_demo_ui_extension.h b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/js_demo_ui_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..1fab78af8e6e07a7f3060b1f42583b39e3125392 --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/include/js_demo_ui_extension.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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_JS_DEMO_UI_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_JS_DEMO_UI_EXTENSION_H + +#include "demo_ui_extension.h" +#include "runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +class JsDemoUIExtension : public DemoUIExtension, + public std::enable_shared_from_this { +public: + explicit JsDemoUIExtension(const std::unique_ptr &runtime); + ~JsDemoUIExtension() override; + + /** + * @brief Create JsDemoUIExtension. + * + * @param runtime The runtime. + * @return The JsDemoUIExtension instance. + */ + static JsDemoUIExtension *Create(const std::unique_ptr &runtime); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_DEMO_UI_EXTENSION_H diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension.cpp b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ca3d04ec5b30134d459f157918eaa96dfb03215 --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 "demo_ui_extension.h" + +#include "hilog_tag_wrapper.h" +#include "js_demo_ui_extension.h" + +namespace OHOS { +namespace AbilityRuntime { +DemoUIExtension *DemoUIExtension::Create(const std::unique_ptr &runtime) +{ + HILOG_DEBUG("Create demo extension."); + if (runtime == nullptr) { + return new DemoUIExtension(); + } + + switch (runtime->GetLanguage()) { + case Runtime::Language::JS: + return JsDemoUIExtension::Create(runtime); + default: + return new (std::nothrow) DemoUIExtension(); + } +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension_module_loader.cpp b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension_module_loader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4f0f2def34673755e510a9fddcec18cc6b6bf34 --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/demo_ui_extension_module_loader.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 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 "demo_ui_extension_module_loader.h" + +#include "demo_ui_extension.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +DemoUIExtensionModuleLoader::DemoUIExtensionModuleLoader() = default; +DemoUIExtensionModuleLoader::~DemoUIExtensionModuleLoader() = default; + +Extension *DemoUIExtensionModuleLoader::Create(const std::unique_ptr &runtime) const +{ + TAG_LOGD(AAFwkTag::TEST, "Create demo uiextension module loader."); + return DemoUIExtension::Create(runtime); +} + +std::map DemoUIExtensionModuleLoader::GetParams() +{ + TAG_LOGD(AAFwkTag::TEST, "Get demo uiextension module params."); + std::map params; + // type means extension type in ExtensionAbilityType of extension_ability_info.h, 5000 means demo_ui_extension. + params.insert(std::pair("type", "5000")); + params.insert(std::pair("name", "DemoUIExtensionAbility")); + return params; +} + +extern "C" __attribute__((visibility("default"))) void *OHOS_EXTENSION_GetExtensionModule() +{ + return &DemoUIExtensionModuleLoader::GetInstance(); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/js_demo_ui_extension.cpp b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/js_demo_ui_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc0f671291a1c5d712728e02f5e9ad0d241c1d9a --- /dev/null +++ b/test/sample/demo_ui_extension/native/demo_ui_extension_ability/src/js_demo_ui_extension.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "js_demo_ui_extension.h" + +#include "hilog_wrapper.h" +#include "js_ui_extension_base.h" + +namespace OHOS { +namespace AbilityRuntime { +JsDemoUIExtension *JsDemoUIExtension::Create(const std::unique_ptr &runtime) +{ + TAG_LOGD(AAFwkTag::TEST, "Create js demo uiextension."); + return new JsDemoUIExtension(runtime); +} + +JsDemoUIExtension::JsDemoUIExtension(const std::unique_ptr &runtime) +{ + TAG_LOGD(AAFwkTag::TEST, "Js demo uiextension constructor."); + auto uiExtensionBaseImpl = std::make_unique(runtime); + SetUIExtensionBaseImpl(std::move(uiExtensionBaseImpl)); +} + +JsDemoUIExtension::~JsDemoUIExtension() +{ + TAG_LOGD(AAFwkTag::TEST, "Js demo uiextension destructor."); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index bdb57ae4659bf7b756b030958b181e467e443266..94d14a21136b1cb3417daaa2d518f2ba8f2dbac9 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -2355,6 +2355,7 @@ ohos_unittest("action_extension_module_loader_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:action_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -2382,6 +2383,7 @@ ohos_unittest("action_extension_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${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}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main", @@ -2415,6 +2417,7 @@ ohos_unittest("share_extension_module_loader_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${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}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main", @@ -2446,6 +2449,7 @@ ohos_unittest("share_extension_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${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}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main", @@ -2541,6 +2545,7 @@ ohos_unittest("embedded_ui_extension_module_loader_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:embedded_ui_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -2568,6 +2573,7 @@ ohos_unittest("embedded_ui_extension_test") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:embedded_ui_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main",