Using modal uiextension to create atomic service panel.

Signed-off-by: benb365 <liuyongchang1@huawei.com>
Change-Id: I1b7231f75d9177f12f07b49a7322a38e5375752e
This commit is contained in:
benb365 2024-06-20 20:08:12 +08:00
parent dea63f25b9
commit 01d685dc2a
16 changed files with 157 additions and 140 deletions

View File

@ -19,18 +19,8 @@
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
namespace OHOS::Ace {
RefPtr<NG::FrameNode> AppBarHelper::CreateUIExtensionNode(const std::string& bundleName,
const std::string& abilityName, const std::map<std::string, std::string>& params,
std::function<void(int32_t)>&& onRelease,
std::function<void(int32_t, const std::string&, const std::string&)>&& onError)
{
return NG::UIExtensionModelNG::Create(bundleName, abilityName, params, std::move(onRelease), std::move(onError));
}
std::string AppBarHelper::QueryAppGalleryBundleName()
{
auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();

View File

@ -87,6 +87,7 @@ ohos_source_set("preview_osal_source") {
"time_event_proxy_preview.cpp",
"trace_id_impl.cpp",
"view_data_wrap_impl.cpp",
"want_wrap_preview.cpp",
]
if (defined(resourceschedule_ffrt_support) &&

View File

@ -19,14 +19,6 @@
namespace OHOS::Ace {
RefPtr<NG::FrameNode> AppBarHelper::CreateUIExtensionNode(const std::string& bundleName,
const std::string& abilityName, const std::map<std::string, std::string>& params,
std::function<void(int32_t)>&& onRelease,
std::function<void(int32_t, const std::string&, const std::string&)>&& onError)
{
return nullptr;
}
std::string AppBarHelper::QueryAppGalleryBundleName()
{
return "";

View File

@ -13,39 +13,11 @@
* limitations under the License.
*/
#include "adapter/ohos/osal/want_wrap_ohos.h"
#include "base/want/want_wrap.h"
namespace OHOS::Ace {
napi_value WantWrap::ConvertToNativeValue(const OHOS::AAFwk::Want& want, NativeEngine* engine)
{
napi_value result = nullptr;
return result;
}
RefPtr<WantWrap> WantWrap::CreateWantWrap(napi_env env, napi_value value)
{
return nullptr;
}
RefPtr<WantWrap> WantWrap::CreateWantWrap(const std::string& bundleName, const std::string& abilityName)
{
return nullptr;
}
WantWrapOhos::WantWrapOhos(napi_env env, napi_value value)
{
}
WantWrapOhos::WantWrapOhos(const std::string& bundleName, const std::string& abilityName)
{
}
void WantWrapOhos::SetWantParamsFromWantWrap(void* want)
{
}
std::string WantWrapOhos::ToString() const
{
return std::string();
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -110,7 +110,7 @@ constexpr uint32_t APP_DOMAIN = 0xC0D0;
namespace OHOS::Ace {
enum AceLogTag : uint8_t {
ACE_DEFAULT_DOMAIN = 0, // C03900
ACE_DEFAULT_DOMAIN = 0, // C03900
ACE_ALPHABET_INDEXER, // C03901
ACE_COUNTER, // C03902
ACE_SUB_WINDOW, // C03903

View File

@ -25,11 +25,6 @@ namespace OHOS::Ace {
class ACE_EXPORT AppBarHelper final {
public:
static RefPtr<NG::FrameNode> CreateUIExtensionNode(const std::string& bundleName,
const std::string& abilityName, const std::map<std::string, std::string>& params,
std::function<void(int32_t)>&& onRelease,
std::function<void(int32_t, const std::string&, const std::string&)>&& onError);
static std::string QueryAppGalleryBundleName();
};

View File

@ -52,6 +52,28 @@ RefPtr<AppBarTheme> GetAppBarTheme()
CHECK_NULL_RETURN(pipeline, nullptr);
return pipeline->GetTheme<AppBarTheme>();
}
#ifndef PREVIEW
void AssembleUiExtensionParams(
bool firstTry, std::string& appGalleryBundleName, std::map<std::string, std::string>& params)
{
auto missionId = AceApplicationInfo::GetInstance().GetMissionId();
params.try_emplace("bundleName", AceApplicationInfo::GetInstance().GetProcessName());
params.try_emplace("abilityName", AceApplicationInfo::GetInstance().GetAbilityName());
params.try_emplace("module", Container::Current()->GetModuleName());
if (missionId != -1) {
params.try_emplace("missionId", std::to_string(missionId));
}
if (firstTry) {
params.try_emplace("ability.want.params.uiExtensionType", "sysDialog/atomicServicePanel");
appGalleryBundleName = OHOS::Ace::SystemProperties::GetAtomicServiceBundleName();
} else {
params.try_emplace("ability.want.params.uiExtensionType", "sys/commonUI");
appGalleryBundleName = OHOS::Ace::AppBarHelper::QueryAppGalleryBundleName();
}
}
#endif
} // namespace
RefPtr<FrameNode> AppBarView::Create(const RefPtr<FrameNode>& stage)
@ -217,12 +239,15 @@ RefPtr<FrameNode> AppBarView::BuildDivider()
void AppBarView::BindMenuCallback(const RefPtr<FrameNode>& menuButton)
{
auto clickCallback = [weakButton = WeakClaim(RawPtr(menuButton))](GestureEvent& info) {
auto clickCallback = [wp = WeakClaim(this)](GestureEvent& info) {
#ifdef PREVIEW
LOGW("[Engine Log] Unable to show the SharePanel in the Previewer. "
"Perform this operation on the emulator or a real device instead.");
#else
auto pipeline = PipelineContext::GetCurrentContext();
auto appbarView = wp.Upgrade();
CHECK_NULL_VOID(appbarView);
auto node = appbarView->atomicService_.Upgrade();
auto pipeline = node->GetContext();
CHECK_NULL_VOID(pipeline);
auto theme = pipeline->GetTheme<AppBarTheme>();
CHECK_NULL_VOID(theme);
@ -231,9 +256,7 @@ void AppBarView::BindMenuCallback(const RefPtr<FrameNode>& menuButton)
theme->GetAbilityName().c_str());
pipeline->FireSharePanelCallback(theme->GetBundleName(), theme->GetAbilityName());
} else {
auto menuButton = weakButton.Upgrade();
CHECK_NULL_VOID(menuButton);
BindContentCover(menuButton);
appbarView->CreateServicePanel(true);
}
#endif
};
@ -264,8 +287,21 @@ void AppBarView::BindCloseCallback(const RefPtr<FrameNode>& closeButton)
}
}
void AppBarView::BindContentCover(const RefPtr<FrameNode>& targetNode, bool firstBind)
void AppBarView::DestroyServicePanel()
{
auto node = atomicService_.Upgrade();
auto pipeline = node->GetContext();
CHECK_NULL_VOID(pipeline);
auto overlayManager = pipeline->GetOverlayManager();
CHECK_NULL_VOID(overlayManager);
overlayManager->CloseModalUIExtension(sessionId_);
LOGI("ServicePanel release session:%{public}d", sessionId_);
}
void AppBarView::CreateServicePanel(bool firstTry)
{
#ifndef PREVIEW
if (OHOS::Ace::SystemProperties::GetAtomicServiceBundleName().empty() &&
OHOS::Ace::AppBarHelper::QueryAppGalleryBundleName().empty()) {
LOGE("UIExtension BundleName is empty.");
@ -277,48 +313,35 @@ void AppBarView::BindContentCover(const RefPtr<FrameNode>& targetNode, bool firs
auto overlayManager = pipeline->GetOverlayManager();
CHECK_NULL_VOID(overlayManager);
std::string stageAbilityName = "";
ModalUIExtensionCallbacks callbacks;
callbacks.onRelease = [wp = WeakClaim(this)](int32_t releaseCode) {
auto bar = wp.Upgrade();
bar->DestroyServicePanel();
};
callbacks.onError = [wp = WeakClaim(this), firstTry](
int32_t code, const std::string& name, const std::string& message) {
auto bar = wp.Upgrade();
bar->DestroyServicePanel();
if (firstTry) {
bar->CreateServicePanel(false);
}
};
std::string abilityName;
auto theme = pipeline->GetTheme<AppBarTheme>();
if (theme) {
stageAbilityName = theme->GetStageAbilityName();
abilityName = theme->GetStageAbilityName();
}
NG::ModalStyle modalStyle;
modalStyle.modalTransition = NG::ModalTransition::NONE;
auto buildNodeFunc = [targetNode, overlayManager, modalStyle, stageAbilityName, firstBind]() -> RefPtr<UINode> {
auto onRelease = [overlayManager, modalStyle, targetNode](int32_t releaseCode) {
auto style = modalStyle;
overlayManager->BindContentCover(
false, nullptr, nullptr, style, nullptr, nullptr, nullptr, nullptr, ContentCoverParam(), targetNode);
};
auto onError = [overlayManager, modalStyle, targetNode, firstBind](
int32_t code, const std::string& name, const std::string& message) {
auto style = modalStyle;
overlayManager->BindContentCover(
false, nullptr, nullptr, style, nullptr, nullptr, nullptr, nullptr, ContentCoverParam(), targetNode);
// if pull up new service panel failed, try to pull up the old one.
if (firstBind) {
BindContentCover(targetNode, false);
}
};
// Create parameters of UIExtension.
std::map<std::string, std::string> params = CreateUIExtensionParams();
// Create UIExtension node.
auto appGalleryBundleName = OHOS::Ace::SystemProperties::GetAtomicServiceBundleName();
if (!firstBind) {
appGalleryBundleName = OHOS::Ace::AppBarHelper::QueryAppGalleryBundleName();
params.erase("ability.want.params.uiExtensionType");
params.try_emplace("ability.want.params.uiExtensionType", "sys/commonUI");
}
auto uiExtNode = OHOS::Ace::AppBarHelper::CreateUIExtensionNode(
appGalleryBundleName, stageAbilityName, params, std::move(onRelease), std::move(onError));
LOGI("UIExtension BundleName: %{public}s, AbilityName: %{public}s", appGalleryBundleName.c_str(),
stageAbilityName.c_str());
InitUIExtensionNode(uiExtNode);
return uiExtNode;
};
overlayManager->BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, nullptr,
nullptr, ContentCoverParam(), targetNode);
std::string appGalleryBundleName;
std::map<std::string, std::string> params;
AssembleUiExtensionParams(firstTry, appGalleryBundleName, params);
auto wantWrap = WantWrap::CreateWantWrap(appGalleryBundleName, abilityName);
wantWrap->SetWantParam(params);
LOGI("ServicePanel request bundle: %{public}s, ability: %{public}s. "
"UIExtension bundle: %{public}s, ability: %{public}s, module: %{public}s",
appGalleryBundleName.c_str(), abilityName.c_str(), params["bundleName"].c_str(), params["abilityName"].c_str(),
params["module"].c_str());
sessionId_ = overlayManager->CreateModalUIExtension(wantWrap, callbacks, false);
#endif
}
void AppBarView::InitUIExtensionNode(const RefPtr<FrameNode>& uiExtNode)
@ -331,23 +354,6 @@ void AppBarView::InitUIExtensionNode(const RefPtr<FrameNode>& uiExtNode)
uiExtNode->MarkModifyDone();
}
std::map<std::string, std::string> AppBarView::CreateUIExtensionParams()
{
auto missionId = AceApplicationInfo::GetInstance().GetMissionId();
std::map<std::string, std::string> params;
params.try_emplace("bundleName", AceApplicationInfo::GetInstance().GetProcessName());
params.try_emplace("abilityName", AceApplicationInfo::GetInstance().GetAbilityName());
params.try_emplace("module", Container::Current()->GetModuleName());
if (missionId != -1) {
params.try_emplace("missionId", std::to_string(missionId));
}
params.try_emplace("ability.want.params.uiExtensionType", "sysDialog/atomicServicePanel");
LOGI("BundleName: %{public}s, AbilityName: %{public}s, Module: %{public}s",
AceApplicationInfo::GetInstance().GetProcessName().c_str(),
AceApplicationInfo::GetInstance().GetAbilityName().c_str(), Container::Current()->GetModuleName().c_str());
return params;
}
std::optional<RectF> AppBarView::GetAppBarRect()
{
auto pipeline = PipelineContext::GetCurrentContext();

View File

@ -54,9 +54,10 @@ private:
RefPtr<FrameNode> BuildDivider();
void BindMenuCallback(const RefPtr<FrameNode>& menuButton);
void BindCloseCallback(const RefPtr<FrameNode>& closeButton);
static void BindContentCover(const RefPtr<FrameNode>& targetNode, bool firstBind = true);
void CreateServicePanel(bool firstTry);
void DestroyServicePanel();
static void InitUIExtensionNode(const RefPtr<FrameNode>& uiExtNode);
static std::map<std::string, std::string> CreateUIExtensionParams();
int32_t sessionId_ = 0;
WeakPtr<FrameNode> atomicService_;
};

View File

@ -4931,6 +4931,13 @@ bool OverlayManager::AddCurSessionId(int32_t sessionId)
return true;
}
int32_t OverlayManager::CreateModalUIExtension(const RefPtr<WantWrap>& wantWrap,
const ModalUIExtensionCallbacks& callbacks, bool isProhibitBack, bool isAsyncModalBinding)
{
auto& want = wantWrap->GetWant();
return CreateModalUIExtension(want, callbacks, isProhibitBack, isAsyncModalBinding);
}
int32_t OverlayManager::CreateModalUIExtension(
const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks,
bool isProhibitBack, bool isAsyncModalBinding, bool isAllowedBeCovered)

View File

@ -25,6 +25,7 @@
#include "base/memory/ace_type.h"
#include "base/memory/referenced.h"
#include "base/utils/noncopyable.h"
#include "base/want/want_wrap.h"
#include "base/utils/utils.h"
#include "core/components/common/properties/placement.h"
#include "core/components/dialog/dialog_properties.h"
@ -44,14 +45,7 @@
#include "core/components_ng/pattern/toast/toast_layout_property.h"
#include "core/components_ng/pattern/toast/toast_view.h"
#include "core/pipeline_ng/ui_task_scheduler.h"
namespace OHOS::Ace {
struct ModalUIExtensionCallbacks;
} // namespace OHOS::Ace
namespace OHOS::AAFwk {
class Want;
} // namespace OHOS::AAFwk
#include "interfaces/inner_api/ace/modal_ui_extension_config.h"
namespace OHOS::Ace::NG {
@ -439,6 +433,8 @@ public:
RefPtr<UINode> FindWindowScene(RefPtr<FrameNode> targetNode);
// ui extension
int32_t CreateModalUIExtension(const RefPtr<WantWrap>& want, const ModalUIExtensionCallbacks& callbacks,
bool isProhibitBack, bool isAsyncModalBinding = false);
int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks,
bool isProhibitBack, bool isAsyncModalBinding = false, bool isAllowedBeCovered = true);
void CloseModalUIExtension(int32_t sessionId);

View File

@ -17,14 +17,6 @@
namespace OHOS::Ace {
RefPtr<NG::FrameNode> AppBarHelper::CreateUIExtensionNode(const std::string& bundleName,
const std::string& abilityName, const std::map<std::string, std::string>& params,
std::function<void(int32_t)>&& onRelease,
std::function<void(int32_t, const std::string&, const std::string&)>&& onError)
{
return nullptr;
}
std::string AppBarHelper::QueryAppGalleryBundleName()
{
return "";

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 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 "base/utils/macros.h"
#include "base/want/want_wrap.h"
namespace OHOS::Ace {
ACE_WEAK_SYM RefPtr<WantWrap> WantWrap::CreateWantWrap(const std::string& bundleName, const std::string& abilityName)
{
return nullptr;
}
} // namespace OHOS::Ace

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 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 "core/components_ng/pattern/app_bar/app_bar_view.h"
namespace OHOS::Ace::NG {
ACE_WEAK_SYM RefPtr<FrameNode> AppBarView::Create(const RefPtr<FrameNode>& stage)
{
return nullptr;
}
ACE_WEAK_SYM void AppBarView::SetStatusBarItemColor(bool isLight)
{
return;
}
ACE_WEAK_SYM std::optional<RectF> AppBarView::GetAppBarRect()
{
return RectF();
}
} // namespace OHOS::Ace::NG

View File

@ -453,7 +453,6 @@ ohos_source_set("ace_engine_unittest_flutter_deps") {
ohos_source_set("ace_components_mock") {
testonly = true
sources = [
"$ace_root/test/mock/adapter/mock_app_bar_helper_impl.cpp",
"$ace_root/test/mock/adapter/mock_file_uri_helper_ohos.cpp",
"$ace_root/test/mock/adapter/mock_image_packer_ohos.cpp",
"$ace_root/test/mock/adapter/mock_modal_ui_extension.cpp",
@ -504,6 +503,7 @@ ohos_source_set("ace_components_mock") {
"$ace_root/test/mock/core/image_provider/mock_image_cache.cpp",
"$ace_root/test/mock/core/image_provider/mock_image_loading_context.cpp",
"$ace_root/test/mock/core/image_provider/mock_image_source_info.cpp",
"$ace_root/test/mock/core/pattern/mock_app_bar_view.cpp",
"$ace_root/test/mock/core/pattern/mock_container_modal_utils.cpp",
"$ace_root/test/mock/core/pipeline/mock_element_register.cpp",
"$ace_root/test/mock/core/pipeline/mock_pipeline_context.cpp",
@ -541,9 +541,6 @@ ohos_source_set("ace_components_pattern") {
"$ace_root/component_ext/movingphoto/movingphoto_pattern.cpp",
"$ace_root/frameworks/core/components_ng/pattern/action_sheet/action_sheet_model_ng.cpp",
"$ace_root/frameworks/core/components_ng/pattern/animator/animator_model_ng.cpp",
"$ace_root/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp",
"$ace_root/frameworks/core/components_ng/pattern/app_bar/atomic_service_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp",
"$ace_root/frameworks/core/components_ng/pattern/badge/badge_accessibility_property.cpp",
"$ace_root/frameworks/core/components_ng/pattern/badge/badge_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/badge/badge_layout_property.cpp",

View File

@ -15,5 +15,15 @@ import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni")
ace_unittest("app_bar_test_ng") {
type = "new"
sources = [ "app_bar_test_ng.cpp" ]
sources = [
"$ace_root/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp",
"$ace_root/frameworks/core/components_ng/pattern/app_bar/atomic_service_layout_algorithm.cpp",
"$ace_root/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp",
"app_bar_test_ng.cpp",
]
mocks = [
"$ace_root/test/mock/adapter/mock_app_bar_helper_impl.cpp",
"$ace_root/test/mock/adapter/mock_want_wrap.cpp",
]
sources += mocks
}

View File

@ -35,7 +35,6 @@ ace_unittest("pipeline_context_test_ng") {
"$ace_root/frameworks/core/pipeline/pipeline_base.cpp",
"$ace_root/frameworks/core/pipeline_ng/pipeline_context.cpp",
"$ace_root/frameworks/core/pipeline_ng/ui_task_scheduler.cpp",
"$ace_root/test/mock/adapter/mock_app_bar_helper_impl.cpp",
"$ace_root/test/mock/adapter/mock_modal_ui_extension.cpp",
"$ace_root/test/mock/adapter/mock_view_data_wrap_ohos.cpp",
"$ace_root/test/mock/base/mock_ace_performance_check.cpp",
@ -82,6 +81,7 @@ ace_unittest("pipeline_context_test_ng") {
"$ace_root/test/mock/core/image_provider/mock_image_file_cache.cpp",
"$ace_root/test/mock/core/image_provider/mock_image_loading_context.cpp",
"$ace_root/test/mock/core/image_provider/mock_image_source_info.cpp",
"$ace_root/test/mock/core/pattern/mock_app_bar_view.cpp",
"$ace_root/test/mock/core/pattern/mock_container_modal_utils.cpp",
"$ace_root/test/mock/core/pipeline/mock_element_register.cpp",
"$ace_root/test/mock/core/render/mock_animation_utils.cpp",