remove ui service dialog

Signed-off-by: lushi <lushi@huawei.com>
Change-Id: I3652a487d7234c5260fd9db3dcb7686213316b50
This commit is contained in:
lushi 2022-10-08 09:58:09 +08:00 committed by lushi1202
parent 626d1ffba4
commit 934667c97f
61 changed files with 124 additions and 2926 deletions

View File

@ -43,7 +43,6 @@ template("ace_ohos_standard_source_set") {
# innerkits impl
"$ace_root/adapter/ohos/entrance/ui_content_impl.cpp",
"$ace_root/adapter/ohos/entrance/ui_dialog_impl.cpp",
# drag window
"$ace_root/adapter/ohos/entrance/window/drag_window_ohos.cpp",

View File

@ -1,345 +0,0 @@
/*
* 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 "adapter/ohos/entrance/ui_dialog_impl.h"
#include "axis_event.h"
#include "dialog_callback_proxy.h"
#include "init_data.h"
#include "key_event.h"
#include "locale_config.h"
#include "pointer_event.h"
#include "res_config.h"
#include "runtime.h"
#include "adapter/ohos/entrance/ace_application_info.h"
#include "adapter/ohos/entrance/ace_container.h"
#include "adapter/ohos/entrance/flutter_ace_view.h"
#include "base/log/log.h"
#include "core/components/theme/app_theme.h"
#ifdef ENABLE_ROSEN_BACKEND
#include "render_service_client/core/ui/rs_ui_director.h"
#endif
namespace OHOS::Ace {
extern "C" ACE_EXPORT void* OHOS_ACE_CreateDialog()
{
return new UIDialogImpl();
}
class UIMgrServiceWindowChangeListener : public Rosen::IWindowChangeListener {
public:
explicit UIMgrServiceWindowChangeListener(WeakPtr<Platform::AceContainer> container)
{
container_ = container;
}
void OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason) override
{
LOGI("UIMgrServiceWindowChangeListener size change");
auto container = container_.Upgrade();
if (container) {
container->SetWindowPos(rect.posX_, rect.posY_);
auto taskExecutor = container->GetTaskExecutor();
if (!taskExecutor) {
LOGE("OnSizeChange: taskExecutor is null.");
return;
}
taskExecutor->PostTask(
[rect, reason, container]() {
auto flutterAceView = static_cast<Platform::FlutterAceView*>(container->GetView());
if (!flutterAceView) {
LOGE("OnSizeChange: flutterAceView is null.");
return;
}
Platform::FlutterAceView::SurfaceChanged(flutterAceView, rect.width_, rect.height_,
rect.height_ >= rect.width_ ? 0 : 1, static_cast<WindowSizeChangeReason>(reason));
},
TaskExecutor::TaskType::PLATFORM);
}
}
void OnModeChange(OHOS::Rosen::WindowMode mode) override
{
LOGI("UIMgrServiceWindowChangeListener mode change");
}
private:
WeakPtr<Platform::AceContainer> container_;
};
class UIMgrServiceInputEventConsumer : public Rosen::IInputEventConsumer {
public:
explicit UIMgrServiceInputEventConsumer(Ace::Platform::FlutterAceView* flutterAceView)
{
flutterAceView_ = flutterAceView;
}
~UIMgrServiceInputEventConsumer() override = default;
bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const override
{
if (flutterAceView_ != nullptr) {
flutterAceView_->DispatchTouchEvent(flutterAceView_, pointerEvent);
return true;
}
return false;
}
bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const override
{
// do nothing
return false;
}
bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const override
{
// do nothing
return false;
}
private:
Ace::Platform::FlutterAceView* flutterAceView_ = nullptr;
};
static void SetDialogBackgroundColor(const OHOS::Ace::RefPtr<OHOS::Ace::PipelineContext>& context)
{
auto themeManager = context->GetThemeManager();
if (themeManager) {
auto appTheme = themeManager->GetTheme<AppTheme>();
if (appTheme) {
LOGI("set bg color TRANSPARENT");
appTheme->SetBackgroundColor(Color::TRANSPARENT);
}
}
}
std::shared_ptr<OHOS::AppExecFwk::Ability> UIDialogImpl::CreateAbility()
{
auto ability = OHOS::AppExecFwk::Ability::Create(nullptr);
if (ability == nullptr) {
LOGE("create ability failed");
return nullptr;
}
auto deal = std::make_shared<OHOS::AppExecFwk::ContextDeal>();
if (deal == nullptr) {
LOGE("create deal failed");
delete ability;
return nullptr;
}
deal->initResourceManager(resourceManager_);
ability->AttachBaseContext(deal);
std::shared_ptr<OHOS::AppExecFwk::Ability> sharedAbility(ability);
return sharedAbility;
}
void UIDialogImpl::InitResourceManager()
{
std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
if (resourceManager == nullptr) {
LOGE("InitResourceManager create resourceManager failed");
return;
}
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
UErrorCode status = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(Global::I18n::LocaleConfig::GetSystemLanguage(), status);
resConfig->SetLocaleInfo(locale);
if (resConfig->GetLocaleInfo() != nullptr) {
LOGD("InitResourceManager language: %{public}s, script: %{public}s, region: %{public}s,",
resConfig->GetLocaleInfo()->getLanguage(), resConfig->GetLocaleInfo()->getScript(),
resConfig->GetLocaleInfo()->getCountry());
} else {
LOGE("InitResourceManager language: GetLocaleInfo is null.");
}
resourceManager->UpdateResConfig(*resConfig);
resourceManager_ = resourceManager;
}
void UIDialogImpl::ShowDialog(const std::string& name, const std::string& params, uint32_t windowType, int x, int y,
int width, int height, const std::function<void(int32_t, const std::string&, const std::string&)>& dialogCallback,
int32_t dialogId)
{
LOGI("UIDialogImpl Show dialog start %{public}d", dialogId);
SetHwIcuDirectory();
InitResourceManager();
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
if (resourceManager_ != nullptr) {
resourceManager_->GetResConfig(*resConfig);
auto localeInfo = resConfig->GetLocaleInfo();
Ace::Platform::AceApplicationInfoImpl::GetInstance().SetResourceManager(resourceManager_);
if (localeInfo != nullptr) {
auto language = localeInfo->getLanguage();
auto region = localeInfo->getCountry();
auto script = localeInfo->getScript();
Ace::AceApplicationInfo::GetInstance().SetLocale((language == nullptr) ? "" : language,
(region == nullptr) ? "" : region, (script == nullptr) ? "" : script, "");
}
}
std::string resPath;
// create container
auto ability = CreateAbility();
Ace::Platform::AceContainer::CreateContainer(
dialogId, Ace::FrontendType::JS, false, "", ability, nullptr, true);
abilityMaps_[dialogId] = ability;
auto container = Ace::Platform::AceContainer::GetContainer(dialogId);
if (!container) {
LOGE("container is null, set configuration failed.");
return;
}
auto aceResCfg = container->GetResourceConfiguration();
aceResCfg.SetOrientation(Ace::SystemProperties::GetDeviceOrientation());
aceResCfg.SetDensity(Ace::SystemProperties::GetResolution());
aceResCfg.SetDeviceType(Ace::SystemProperties::GetDeviceType());
container->SetResourceConfiguration(aceResCfg);
container->SetPackagePathStr(resPath);
Ace::Platform::AceContainer::SetDialogCallback(
dialogId, [callback = dialogCallback, id = dialogId](const std::string& event, const std::string& params) {
LOGI("Dialog callback from ace container");
callback(id, event, params);
});
// create view.
auto flutterAceView = Ace::Platform::FlutterAceView::CreateView(dialogId, true);
sptr<OHOS::Rosen::WindowOption> option = new OHOS::Rosen::WindowOption();
LOGI("Show dialog: windowConfig: x: %{public}d, y: %{public}d, width: %{public}d, height: %{public}d", x, y, width,
height);
option->SetWindowRect({ x, y, width, height });
option->SetWindowType(static_cast<OHOS::Rosen::WindowType>(windowType));
option->SetMainHandlerAvailable(false);
std::string windowName = "system_dialog_window";
windowName += std::to_string(dialogId);
auto dialogWindow = OHOS::Rosen::Window::Create(windowName, option);
if (dialogWindow == nullptr) {
LOGE("Create window failed");
return;
}
// register surface change callback
OHOS::sptr<OHOS::Rosen::IWindowChangeListener> listener =
new UIMgrServiceWindowChangeListener(AceType::WeakClaim(AceType::RawPtr(container)));
dialogWindow->RegisterWindowChangeListener(listener);
std::shared_ptr<Rosen::IInputEventConsumer> inputEventListener =
std::make_shared<UIMgrServiceInputEventConsumer>(flutterAceView);
dialogWindow->SetInputEventConsumer(inputEventListener);
Ace::Platform::FlutterAceView::SurfaceCreated(flutterAceView, dialogWindow);
// set metrics
flutter::ViewportMetrics metrics;
metrics.physical_width = width;
metrics.physical_height = height;
metrics.device_pixel_ratio = density_;
Ace::Platform::FlutterAceView::SetViewportMetrics(flutterAceView, metrics);
std::string packagePathStr = "/system/etc/SADialog/";
std::vector<std::string> assetBasePathStr = { name + "/" };
Ace::Platform::AceContainer::AddAssetPath(dialogId, packagePathStr, "", assetBasePathStr);
Ace::Platform::UIEnvCallback callback = nullptr;
callback =
#ifdef ENABLE_ROSEN_BACKEND
[dialogWindow, listener, dialogId](const OHOS::Ace::RefPtr<OHOS::Ace::PipelineContext>& context) mutable {
if (SystemProperties::GetRosenBackendEnabled()) {
auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create();
if (rsUiDirector != nullptr) {
rsUiDirector->SetRSSurfaceNode(dialogWindow->GetSurfaceNode());
dialogWindow->RegisterWindowChangeListener(listener);
rsUiDirector->SetUITaskRunner(
[taskExecutor = Ace::Platform::AceContainer::GetContainer(dialogId)->GetTaskExecutor()](
const std::function<void()>& task) {
taskExecutor->PostTask(task, TaskExecutor::TaskType::UI);
});
if (context != nullptr) {
context->SetRSUIDirector(rsUiDirector);
}
rsUiDirector->Init();
LOGI("Init Rosen Backend");
}
} else {
LOGI("not Init Rosen Backend");
}
SetDialogBackgroundColor(context);
};
#else
[](const OHOS::Ace::RefPtr<OHOS::Ace::PipelineContext>& context) { SetDialogBackgroundColor(context); }
#endif
// set view
Ace::Platform::AceContainer::SetView(
flutterAceView, density_, width, height, dialogWindow, callback);
Ace::Platform::AceContainer::SetUIWindow(dialogId, dialogWindow);
Ace::Platform::FlutterAceView::SurfaceChanged(flutterAceView, width, height, 0);
container->SetWindowPos(x, y);
// run page.
Ace::Platform::AceContainer::RunPage(
dialogId, Ace::Platform::AceContainer::GetContainer(dialogId)->GeneratePageId(), "", params);
dialogWindow->Show();
dialogWindow->MoveTo(x, y);
dialogWindow->Resize(width, height);
LOGI("Show dialog in service end");
}
void UIDialogImpl::CancelDialog(int32_t id, const std::function<void()>& destroyCallback)
{
LOGI("UIDialogImpl Cancel dialog id: %{public}d", id);
int ret = abilityMaps_.erase(id);
if (ret == 0) {
LOGE("Cancel dialog failed: no such dialog(%{public}d)", id);
return;
}
auto container = Platform::AceContainer::GetContainer(id);
if (!container) {
LOGE("Container(%{public}d) not found.", id);
return;
}
auto dialogWindow = Platform::AceContainer::GetUIWindow(id);
if (dialogWindow) {
dialogWindow->Destroy();
}
#ifdef ENABLE_ROSEN_BACKEND
auto taskExecutor = Platform::AceContainer::GetContainer(id)->GetTaskExecutor();
taskExecutor->PostTask(
[id]() {
if (auto context = AceType::DynamicCast<PipelineContext>(
Ace::Platform::AceContainer::GetContainer(id)->GetPipelineContext())) {
context->SetRSUIDirector(nullptr);
}
},
TaskExecutor::TaskType::UI);
#endif
Platform::AceContainer::DestroyContainer(id, destroyCallback);
}
void UIDialogImpl::UpdateDialog(int id, const std::string& data)
{
LOGI("UIDialogImpl Update dialog id: %{public}d", id);
auto container = Platform::AceContainer::GetContainer(id);
if (!container) {
LOGE("Container(%{public}d) not found.", id);
return;
}
Platform::AceContainer::OnDialogUpdated(id, data);
}
} // namespace OHOS::Ace

View File

@ -1,57 +0,0 @@
/*
* 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.
*/
#ifndef FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_UI_DIALOG_IMPL_H
#define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_UI_DIALOG_IMPL_H
#include "interfaces/inner_api/ace/ui_dialog_base.h"
#include "ability.h"
#include "resource_manager.h"
#include "base/utils/macros.h"
namespace OHOS::Ace {
class ACE_EXPORT UIDialogImpl : public UIDialogBase {
public:
UIDialogImpl() = default;
~UIDialogImpl() override = default;
// show system dialog
virtual void ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const std::function<void(int32_t, const std::string&, const std::string&)>& dialogCallback,
int32_t dialogId) override;
// update system dialog
virtual void UpdateDialog(int id, const std::string& data) override;
// cancel system dialog
virtual void CancelDialog(int32_t id, const std::function<void()>& destroyCallback) override;
private:
std::shared_ptr<OHOS::AppExecFwk::Ability> CreateAbility();
void InitResourceManager();
std::shared_ptr<Global::Resource::ResourceManager> resourceManager_;
std::unordered_map<int32_t, std::shared_ptr<OHOS::AppExecFwk::Ability>> abilityMaps_;
float density_ = 2.0f;
};
}
#endif

View File

@ -12,10 +12,7 @@
# limitations under the License.
group("services_target") {
deps = [
"uiservice:uiservice",
"uiservice/uiservice_plugins/uiservice_dialog:uiservicedialog",
]
deps = [ "uiservice:uiservice" ]
}
group("unittest") {

View File

@ -38,14 +38,11 @@ config("uiservicems_config") {
"include/",
"$ability_runtime_inner_api_path/base/include",
"$ability_runtime_services_path/common/include",
"$ace_root/adapter/ohos/services/uiservice",
"$ace_root/adapter/ohos/services/uiservice/uiservice_plugins",
"//commonlibrary/c_utils/base/include",
"//utils/system/safwk/native/include",
"//prebuilts/jdk/jdk8/linux-x86/include",
"//prebuilts/jdk/jdk8/linux-x86/include/linux",
"//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager/include",
"//foundation/windowmanager/interfaces/innerkits",
]
cflags = []
if (target_cpu == "arm") {
@ -69,27 +66,17 @@ template("uiservice_static") {
]
deps = [
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/uiservice_plugins/uiservice_dialog:uiservicedialog",
"//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
]
deps += [ "$ace_root/adapter/ohos/services/uiservice/dialog_ui/dialog_picker/js:dialog_picker_js_files_etc" ]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:runtime",
"appspawn:appspawn_socket_client",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"window_manager:libwm",
]
}
}

View File

@ -1,45 +0,0 @@
# Copyright (c) 2021-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.
import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni")
gen_sa_dialog_js("dialog_picker_js_files_etc") {
project_path = "//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/dialog_ui/dialog_picker/js"
i18n_files = [
"i18n/en-US.json",
"i18n/zh-CN.json",
]
common_files = [
"common/handle_down.png",
"common/handle_down.svg",
"common/handle_up.png",
"common/handle_up.svg",
"common/ic_apk.png",
"common/ic_calendar.png",
"common/ic_contacts.png",
"common/ic_doc.png",
"common/ic_documents.png",
"common/ic_file_multiple.png",
"common/ic_html.png",
"common/ic_image.png",
"common/ic_mp3.png",
"common/ic_pdf.png",
"common/ic_pptx.png",
"common/ic_unknown.png",
"common/ic_video.png",
"common/ic_xls.png",
]
dialog_name = "dialog_picker_service"
part_name = ace_engine_part
subsystem_name = ace_engine_subsystem
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64px" height="24px" viewBox="0 0 64 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 63.1 (92452) - https://sketch.com -->
<title>handle_down</title>
<desc>Created with Sketch.</desc>
<g id="handle_down" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" opacity="0.2" stroke-linecap="round">
<g id="BottomSheet/Handle/down" stroke="#18181A" stroke-width="4">
<path d="M17,9 L30.5854554,14.4083303 C31.5395508,14.7881529 32.6031802,14.7864788 33.5560752,14.4036547 L47.006419,9 L47.006419,9" id="路径"></path>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64px" height="24px" viewBox="0 0 64 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 63.1 (92452) - https://sketch.com -->
<title>handle_up</title>
<desc>Created with Sketch.</desc>
<g id="handle_up" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" opacity="0.2" stroke-linecap="round">
<g id="BottomSheet/Handle/up" stroke="#18181A" stroke-width="4">
<path d="M17,9 L30.5854554,14.4083303 C31.5395508,14.7881529 32.6031802,14.7864788 33.5560752,14.4036547 L47.006419,9 L47.006419,9" id="路径" transform="translate(32.003210, 12.000000) scale(1, -1) translate(-32.003210, -12.000000) "></path>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 796 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,15 +0,0 @@
{
"message": {
"hello": "hello world"
},
"strings": {
"btnCopy": "copy",
"btnPrint": "print",
"uri": "network uri: ",
"unknownName": "unknown file name",
"fileSize": "file size is ",
"sameFile": "same format file",
"unSameFile": "different format file",
"totalSize": "total size is "
},
}

View File

@ -1,15 +0,0 @@
{
"message": {
"hello": "你好世界"
},
"strings": {
"btnCopy": "复制",
"btnPrint": "打印",
"uri": "网页地址: ",
"defaultName": "未知文件名称",
"fileSize": "文件大小",
"sameFile": "个同类文件",
"unSameFile": "个不同类文件",
"totalSize": "总大小"
}
}

View File

@ -1,120 +0,0 @@
.container {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
left: 0vp;
top: 0vp;
width: 100%;
height: 100%;
}
.sharePannel {
width:519vp;
background-color: #FAFAFA;
}
.share {
border-radius: 0vp 0vp 24vp 24vp;
background-color: #FAFAFA;
flex-direction: column;
}
.shareBack {
justify-content: center;
flex-shrink: 0;
}
.backImage {
width: 64vp;
height: 24vp;
}
.shareCard {
margin: 8vp 12vp 8vp 12vp; /* 上 右 下 左*/
background-color: #FFFFFF;
flex-direction: column;
flex-shrink: 0;
}
.shareInfo {
flex-direction: row;
}
.shareIcon {
width: 42vp;
height: 48vp;
background-color: #FFFFFFFF;
}
.shareText {
flex-direction: column;
}
.mainText {
font-family: sans-serif;
font-size: 14vp;
max-lines: 2;
text-overflow: ellipsis;
color: rgba(0, 0, 0, 1);
}
.subText {
height: 14vp;
font-family: sans-serif;
font-size: 10vp;
color: rgba(0, 0, 0, 1);
max-lines: 1;
text-overflow: ellipsis;
word-break: break-all;
}
.button1 {
width: 25vp;
height: 16vp;
font-size: 12vp;
font-family: sans-serif;
color: rgba(0, 125, 255, 1);
}
.button2 {
left: 24vp;
width: 25vp;
height: 16vp;
font-size: 12vp;
font-family: sans-serif;
color: rgba(0, 125, 255, 1);
}
.swiper {
indicator-size: 4vp;
indicator-top: 90%;
}
.shareAppSelect {
margin-left: 15vp;
margin-right: 15vp;
flex-direction: row;
flex-wrap: wrap;
}
/* icon + name */
.shareApp {
margin-left: 15vp;
flex-direction: column;
}
.AppIcon {
height: 48vp;
width: 48vp;
margin: 8vp;
border-radius: 8vp;
}
.AppName {
width: 64vp;
height: 16vp;
font-size: 12vp;
text-align: center;
color:rgba(0, 0, 0, 1);
}

View File

@ -1,28 +0,0 @@
<div class="container">
<div class="share" style="width: {{share.width}}; height: {{share.height}};">
<div class="shareBack" style="margin-top: {{share.backTop}};">
<image class="backImage" onclick="onBack" src="{{share.backIcon}}"></image>
</div>
<div class="shareCard" style="width: {{share.card.width}}; height: {{share.card.height}}; border-radius: {{share.card.radius}};">
<div class="shareInfo" style="margin: {{share.card.contentMargin}}">
<image class="shareIcon" style="border: {{viewStyle.iconBoard}};" src="{{viewStyle.icon}}"></image>
<div class="shareText" style="left: {{share.card.text.left}}; top: {{share.card.text.top}};">
<text class="mainText" style="height: {{viewStyle.textMainHeight}}; width: {{share.card.text.main.width}};">{{previewCard.mainText}}</text>
<text class="subText" style="visibility: {{viewStyle.textVisible}}; top: {{share.card.text.sub.top}}; width: {{share.card.text.sub.width}};">{{previewCard.subText}}</text>
</div>
</div>
<div style="left: {{share.card.btn.left}};">
<text class="button1" style="visibility: {{viewStyle.copyVisible}};">{{viewStyle.button1}}</text>
<text class="button2" style="visibility: {{viewStyle.printVisible}};">{{viewStyle.button2}}</text>
</div>
</div>
<swiper class="swiper" style="height: {{share.swiper.height}};">
<div class="shareAppSelect" style="margin-top: {{share.swiper.select.marginTop}};" for="shareHapList">
<div class="shareApp" for="{{$item}}" onClick="onShare({{$item}})">
<image class="AppIcon" src="{{$item.icon}}"></image>
<text class="AppName">{{$item.name}}</text>
</div>
</div>
</swiper>
</div>
</div>

View File

@ -1,230 +0,0 @@
import router from '@system.router'
import resourceManager from '@ohos.resourceManager';
export default {
data: {
shareHapList: [],
lineNums: 6,
iconBorad: "0.25vp solid #000000",
viewStyle: {
textVisible: "visible",
copyVisible: "hidden",
printVisible: "hidden",
textMainHeight: "19vp",
icon: "",
iconBoard: "",
format: "png",
button1: "",
button2: "",
},
share: {
width: "519vp",
height: "256vp",
backTop: "6vp",
backIcon: "common/handle_down.png",
card: {
width: "495vp",
height: "87vp",
radius: "24vp",
contentMargin: "16vp 43.5vp 6vp 16vp",
text: {
top: "3vp",
left: "16vp",
main:{
width: "380vp",
},
sub: {
top: "2vp",
width: "380vp",
},
},
btn:{
left: "405vp",
}
},
swiper: {
height: "115vp",
select: {
marginTop: "16vp",
}
}
},
},
onInit() {
if (this.deviceType == "phone") {
console.log("this is phone devices");
this.getHapListStyle();
}
this.getViewStyle();
let shareHap = [];
for (let i = 0; i < this.hapList.length; i++) {
shareHap.push(this.hapList[i]);
if (i % this.lineNums == this.lineNums - 1 || i == this.hapList.length - 1) {
this.shareHapList.push(shareHap);
shareHap = [];
}
}
this.getHapResource();
},
onShare: function (item) {
let param = item.bundle + ";" + item.ability;
console.log("dialog service share to :" + item.ability);
callNativeHandler('SHARE_EVENT', param);
},
changeSize: function (param) {
callNativeHandler('CLOSE_EVENT', "");
},
onBack: function () {
console.log("dialog service close");
callNativeHandler('CLOSE_EVENT', "");
},
getViewStyle() {
this.viewStyle.button1 = this.$t('strings.btnCopy');
this.viewStyle.button2 = this.$t('strings.btnPrint');
let defaultIcon = "";
let fileNums = this.previewCard.fileList == null ? 0 : this.previewCard.fileList.length;
if (this.previewCard.type == "text/plain") {
this.viewStyle.textVisible = "hidden"
this.viewStyle.textMainHeight = "38vp";
defaultIcon = "ic_documents";
} else if (this.previewCard.type == "text/html") {
defaultIcon = "ic_html";
this.previewCard.subText = this.$t('strings.uri') + this.previewCard.subText;
} else if (fileNums == 0) {
defaultIcon = "ic_unknown";
if (this.previewCard.type == null) {
if (this.previewCard.subText != null) {
defaultIcon = "ic_html";
this.previewCard.subText = this.$t('strings.uri') + this.previewCard.subText;
} else if (this.previewCard.mainText != null) {
this.viewStyle.textVisible = "hidden"
this.viewStyle.textMainHeight = "38vp";
defaultIcon = "ic_documents";
}
}
if (defaultIcon == "ic_unknown") {
this.previewCard.mainText = this.$t('strings.defaultName');
this.previewCard.subText = this.$t('strings.fileSize') + " KB";
}
} else if (fileNums == 1) {
this.previewCard.mainText = this.previewCard.fileList[0].name;
this.previewCard.subText = this.$t('strings.fileSize') + Math.round(this.previewCard.fileList[0].size / 1024) + "KB";
if (this.previewCard.type.indexOf("image/") != -1) {
defaultIcon = "ic_image";
} else if (this.previewCard.type.indexOf("application/apk") != -1) {
defaultIcon = "ic_apk";
} else if (this.previewCard.type.indexOf("application/pdf") != -1) {
defaultIcon = "ic_pdf";
} else if (this.previewCard.type.indexOf("application/doc") != -1) {
defaultIcon = "ic_doc";
} else if (this.previewCard.type.indexOf("application/ppt") != -1) {
defaultIcon = "ic_pptx";
} else if (this.previewCard.type.indexOf("application/xls") != -1) {
defaultIcon = "ic_xls";
} else if (this.previewCard.type.indexOf("application/ics") != -1) {
defaultIcon = "ic_calendar";
} else if (this.previewCard.type.indexOf("application/vcf") != -1) {
defaultIcon = "ic_contacts";
} else if (this.previewCard.type.indexOf("video/") != -1) {
defaultIcon = "ic_video";
} else if (this.previewCard.type.indexOf("audio/") != -1) {
defaultIcon = "ic_mp3";
} else {
defaultIcon = "ic_unknown";
}
if (this.previewCard.mainText == "") {
this.previewCard.mainText = this.$t('strings.defaultName');
}
} else {
defaultIcon = "ic_file_multiple";
if (this.previewCard.type.indexOf("*") != -1) {
this.previewCard.mainText = fileNums + this.$t('strings.sameFile');
} else {
this.previewCard.mainText = fileNums + this.$t('strings.unSameFile');
}
let totalSize = 0;
for (let i = 0; i < fileNums; i++) {
if (this.previewCard.fileList[i].size != null) {
totalSize += this.previewCard.fileList[i].size;
}
}
this.previewCard.subText = this.$t('strings.totalSize') + Math.round(totalSize / 1024) + "KB";
}
this.viewStyle.icon = "common/" + defaultIcon + "." + this.viewStyle.format;
},
getHapListStyle() {
if (this.deviceType == "phone") {
this.lineNums = 8;
}
this.share.width = "360vp";
this.share.height = "347vp";
this.share.backTop = "0vp";
this.share.card.width = "336vp";
this.share.card.height = "96vp";
this.share.card.radius = "16vp";
this.share.card.contentMargin = "16vp 24vp 8vp 16vp";
this.share.card.text.top = "6vp";
this.share.card.text.left = "12vp";
this.share.card.text.main.width = "236vp";
this.share.card.text.sub.top = "4vp";
this.share.card.text.sub.width = "236vp";
this.share.card.btn.left = "254vp";
this.share.swiper.height = "200vp";
this.share.swiper.select.marginTop = "8vp";
},
getHapResource() {
this.labelMap = new Map()
for (let i = 0; i < this.hapList.length; i++) {
let lableId = Number(this.hapList[i].name);
resourceManager.getResourceManager(this.hapList[i].bundle).then(mgr =>{
console.log("dialog service bundle:" + this.hapList[i].bundle + "---lableId:" + lableId);
mgr.getString(lableId).then(value => {
console.log("dialog service get label(" + lableId + ") value:" + value);
this.updateHapName(this.hapList[i].bundle, value);
}).catch(error => {
console.log("dialog service resource getString error:" + error);
})
}).catch(error => {
console.log("dialog service getResourceManager error:" + error);
});
let iconId = Number(this.hapList[i].icon);
resourceManager.getResourceManager(this.hapList[i].bundle).then(mgr =>{
console.log("dialog service bundle:" + this.hapList[i].bundle + "---iconId:" + iconId);
mgr.getMediaBase64(iconId).then(value => {
console.log("dialog service get icon(" + iconId + ") value:" + value);
this.updateHapIcon(this.hapList[i].bundle, value);
}).catch(error => {
console.log("dialog service resource getString error:" + error);
})
}).catch(error => {
console.log("dialog service getResourceManager error:" + error);
});
}
},
updateHapName(bundle, hapLabel) {
for (let i = 0; i < this.shareHapList.length; i++) {
if (this.shareHapList[i] != null) {
for (let j = 0; j < this.shareHapList[i].length; j++) {
if (this.shareHapList[i][j].bundle == bundle) {
this.shareHapList[i][j].name = hapLabel;
console.log("dialog service update bundle:" + bundle + " to lable:" + hapLabel);
}
}
}
}
},
updateHapIcon(bundle, hapIcon) {
for (let i = 0; i < this.shareHapList.length; i++) {
if (this.shareHapList[i] != null) {
for (let j = 0; j < this.shareHapList[i].length; j++) {
if (this.shareHapList[i][j].bundle == bundle) {
this.shareHapList[i][j].icon = hapIcon;
console.log("dialog service update bundle:" + bundle + " to icon:" + hapIcon);
}
}
}
}
}
}

View File

@ -1,39 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_DIALOG_CALLBACK_INTERFACE_H
#define OHOS_ACE_DIALOG_CALLBACK_INTERFACE_H
#include "dialog_callback.h"
#include "iremote_broker.h"
namespace OHOS {
namespace Ace {
class IDialogCallback : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ace.DialogCallback");
enum {
UI_SERVICE_DIALOG_CALLBACK,
};
/**
* @brief Called back to dialog
*
*/
virtual void OnDialogCallback(int32_t id, const std::string& event, const std::string& params) = 0;
};
} // namespace Ace
} // namespace OHOS
#endif // OHOS_ACE_DIALOG_CALLBACK_INTERFACE_H

View File

@ -1,33 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_DIALOG_CALLBACK_PROXY_H
#define OHOS_ACE_DIALOG_CALLBACK_PROXY_H
#include <iremote_proxy.h>
#include "dialog_callback_interface.h"
namespace OHOS {
namespace Ace {
class DialogCallbackProxy : public IRemoteProxy<IDialogCallback> {
public:
explicit DialogCallbackProxy(const sptr<IRemoteObject> &remote);
virtual ~DialogCallbackProxy();
void OnDialogCallback(int32_t id, const std::string& event, const std::string& params) override;
private:
static inline BrokerDelegator<DialogCallbackProxy> delegator_;
};
} // namespace Ace
} // namespace OHOS
#endif // OHOS_ACE_DIALOG_CALLBACK_PROXY_H

View File

@ -1,61 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_DIALOG_CALLBACK_STUB_H
#define OHOS_ACE_DIALOG_CALLBACK_STUB_H
#include <memory>
#include <map>
#include "dialog_callback_interface.h"
#include "nocopyable.h"
#include <iremote_object.h>
#include <iremote_stub.h>
namespace OHOS {
namespace Ace {
class DialogCallbackStub : public IRemoteStub<IDialogCallback> {
public:
explicit DialogCallbackStub(DialogCallback callback);
virtual ~DialogCallbackStub();
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
void OnDialogCallback(int32_t id, const std::string& event, const std::string& params) override;
private:
int OnDialogCallBackInner(MessageParcel& data, MessageParcel& reply);
DialogCallback callback_;
DISALLOW_COPY_AND_MOVE(DialogCallbackStub);
};
/**
* @class DialogCallbackRecipient
* DialogCallbackRecipient notices IRemoteBroker died.
*/
class DialogCallbackRecipient : public IRemoteObject::DeathRecipient {
public:
using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject>&)>;
explicit DialogCallbackRecipient(RemoteDiedHandler handler);
virtual ~DialogCallbackRecipient();
virtual void OnRemoteDied(const wptr<IRemoteObject>& remote);
private:
RemoteDiedHandler handler_;
};
} // namespace Ace
} // namespace OHOS
#endif // OHOS_ACE_DIALOG_CALLBACK_STUB_H

View File

@ -19,21 +19,16 @@
#include <memory>
#include <singleton.h>
#include <thread_ex.h>
#include <unistd.h>
#include <unordered_map>
#include "client_socket.h"
#include "element_name.h"
#include "event_handler.h"
#include "event_runner.h"
#include "hilog_wrapper.h"
#include "iremote_object.h"
#include "runtime.h"
#include "system_ability.h"
#include "ui_service_mgr_stub.h"
#include "uiservice_dialog/uiservice_dialog_interface.h"
#include "uri.h"
namespace OHOS {
namespace Ace {
@ -41,12 +36,6 @@ using EventRunner = OHOS::AppExecFwk::EventRunner;
using EventHandler = OHOS::AppExecFwk::EventHandler;
enum class UIServiceRunningState { STATE_NOT_START, STATE_RUNNING };
using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty;
union AppSpawnPidMsg {
pid_t pid = 0;
char pidBuf[sizeof(pid_t)];
};
class UIMgrService : public SystemAbility,
public UIServiceMgrStub,
public std::enable_shared_from_this<UIMgrService> {
@ -57,63 +46,22 @@ public:
void OnStop() override;
UIServiceRunningState QueryServiceState() const;
int RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) override;
int UnregisterCallBack(const AAFwk::Want& want) override;
int Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
int32_t RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) override;
int32_t UnregisterCallBack(const AAFwk::Want& want) override;
int32_t Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
const std::string& data, const std::string& extraData) override;
int Request(const AAFwk::Want& want, const std::string& name, const std::string& data) override;
int ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
int32_t Request(const AAFwk::Want& want, const std::string& name, const std::string& data) override;
int32_t ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
const std::string& extraData) override;
int32_t AttachToUiService(const sptr<IRemoteObject>& dialog, int32_t pid) override;
int ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id = nullptr) override;
int CancelDialog(int id) override;
int UpdateDialog(int id, const std::string& data) override;
int32_t RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params) override;
int Dump(int fd, const std::vector<std::u16string>& args) override;
/**
* GetEventHandler, get the ui_service manager service's handler.
*
* @return Returns EventHandler ptr.
*/
std::shared_ptr<EventHandler> GetEventHandler();
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
private:
struct DialogParam {
std::string name;
std::string params;
uint32_t windowType;
int32_t x;
int32_t y;
int32_t width;
int32_t height;
int32_t id;
};
bool Init();
bool CheckCallBackFromMap(const std::string& key);
int HandleRegister(const AAFwk::Want& want, const sptr<IUIService>& uiService);
int HandleUnregister(const AAFwk::Want& want);
int32_t OpenAppSpawnConnection();
void CloseAppSpawnConnection();
AppSpawnMsg* MakeAppSpawnMsg(const std::string& name, int32_t id);
int32_t HandleRegister(const AAFwk::Want& want, const sptr<IUIService>& uiService);
int32_t HandleUnregister(const AAFwk::Want& want);
std::string GetCallBackKeyStr(const AAFwk::Want& want);
std::shared_ptr<EventRunner> eventLoop_;
@ -122,18 +70,6 @@ private:
std::map<std::string, sptr<IUIService>> callbackMap_;
std::mutex uiMutex_;
// app spawn client socket
std::shared_ptr<AppSpawn::ClientSocket> clientSocket_;
std::mutex dialogMapMutex_;
std::unordered_map<int32_t, sptr<OHOS::Ace::IUiServiceDialog>> dialogMap_; // dialog ID vs dialog client
std::unordered_map<int32_t, DialogParam> dialogRecords_; // pid vs dialog params
std::unordered_map<int32_t, int32_t> dialogIDMap_; // dialog ID vs dialog Pid
std::unordered_map<int32_t, sptr<OHOS::Ace::IDialogCallback>> dialogCallbackProxyMap_;
};
} // namespace Ace
} // namespace OHOS

View File

@ -32,40 +32,20 @@ public:
{}
~UIServiceMgrProxy() override = default;
int RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) override;
int32_t RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) override;
virtual int UnregisterCallBack(const AAFwk::Want& want) override;
int32_t UnregisterCallBack(const AAFwk::Want& want) override;
virtual int Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
int32_t Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
const std::string& data, const std::string& extraData) override;
virtual int Request(const AAFwk::Want& want, const std::string& name, const std::string& data) override;
int32_t Request(const AAFwk::Want& want, const std::string& name, const std::string& data) override;
virtual int ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
int32_t ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
const std::string& extraData) override;
virtual int ShowDialog(const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id = nullptr) override;
virtual int CancelDialog(int id) override;;
virtual int UpdateDialog(int id, const std::string& data) override;;
int32_t AttachToUiService(const sptr<IRemoteObject>& dialog, int32_t pid) override;
int32_t RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params) override;
private:
bool WriteInterfaceToken(MessageParcel& data);
static bool WriteInterfaceToken(MessageParcel& data);
private:
static inline BrokerDelegator<UIServiceMgrProxy> delegator_;
};
} // namespace Ace

View File

@ -33,22 +33,17 @@ namespace Ace {
class UIServiceMgrStub : public IRemoteStub<IUIServiceMgr> {
public:
UIServiceMgrStub();
virtual ~UIServiceMgrStub();
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
~UIServiceMgrStub() override;
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
private:
int RegisterCallBackInner(MessageParcel& data, MessageParcel& reply);
int UnregisterCallBackInner(MessageParcel& data, MessageParcel& reply);
int PushInner(MessageParcel& data, MessageParcel& reply);
int RequestInner(MessageParcel& data, MessageParcel& reply);
int ReturnRequestInner(MessageParcel& data, MessageParcel& reply);
int ShowDialogInner(MessageParcel& data, MessageParcel& reply);
int CancelDialogInner(MessageParcel& data, MessageParcel& reply);
int UpdateDialogInner(MessageParcel &data, MessageParcel &reply);
int32_t AttachToUiServiceInner(MessageParcel &data, MessageParcel &reply);
int32_t RemoteDialogCallbackInner(MessageParcel &data, MessageParcel &reply);
int32_t RegisterCallBackInner(MessageParcel& data, MessageParcel& reply);
int32_t UnregisterCallBackInner(MessageParcel& data, MessageParcel& reply);
int32_t PushInner(MessageParcel& data, MessageParcel& reply);
int32_t RequestInner(MessageParcel& data, MessageParcel& reply);
int32_t ReturnRequestInner(MessageParcel& data, MessageParcel& reply);
using RequestFuncType = int (UIServiceMgrStub ::*)(MessageParcel& data, MessageParcel& reply);
using RequestFuncType = int32_t (UIServiceMgrStub ::*)(MessageParcel& data, MessageParcel& reply);
std::map<uint32_t, RequestFuncType> requestFuncMap_;
};
} // namespace Ace

View File

@ -1,66 +0,0 @@
/*
* 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 "dialog_callback_proxy.h"
#include "hilog_wrapper.h"
#include "message_parcel.h"
namespace OHOS {
namespace Ace {
DialogCallbackProxy::DialogCallbackProxy(const sptr<IRemoteObject> &remote)
: IRemoteProxy<IDialogCallback>(remote)
{}
DialogCallbackProxy::~DialogCallbackProxy()
{}
void DialogCallbackProxy::OnDialogCallback(int32_t id, const std::string& event, const std::string& params)
{
auto remote = Remote();
if (remote == nullptr) {
HILOG_ERROR("Ace %{public}s remote is nullptr", __func__);
return;
}
OHOS::MessageParcel dataParcel;
OHOS::MessageParcel reply;
OHOS::MessageOption option;
if (!dataParcel.WriteInterfaceToken(DialogCallbackProxy::GetDescriptor())) {
HILOG_ERROR("Ace %{public}s dataParcel.WriteInterfaceToken(GetDescriptor()) return false", __func__);
return;
}
if (!dataParcel.WriteInt32(id)) {
HILOG_ERROR("Ace fail to WriteInt32 id");
return;
}
if (!dataParcel.WriteString(event)) {
HILOG_ERROR("Ace fail to WriteString event");
return;
}
if (!dataParcel.WriteString(params)) {
HILOG_ERROR("Ace fail to WriteString params");
return;
}
int result = remote->SendRequest(IDialogCallback::UI_SERVICE_DIALOG_CALLBACK, dataParcel, reply, option);
if (result == ERR_NONE) {
HILOG_INFO("Ace %{public}s SendRequest ok, retval is %{public}d", __func__, reply.ReadInt32());
return;
} else {
HILOG_ERROR("Ace %{public}s SendRequest error, result=%{public}d", __func__, result);
return;
}
}
} // namespace Ace
} // namespace OHOS

View File

@ -1,79 +0,0 @@
/*
* 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 "dialog_callback_stub.h"
#include "hilog_wrapper.h"
#include "ui_service_stub.h"
namespace OHOS {
namespace Ace {
DialogCallbackStub::DialogCallbackStub(DialogCallback callback)
{
callback_ = callback;
}
DialogCallbackStub::~DialogCallbackStub()
{
}
void DialogCallbackStub::OnDialogCallback(int32_t id, const std::string& event, const std::string& params)
{
HILOG_INFO("Ace DialogCallbackStub::OnDialogCallback id: %{public}d", id);
callback_(id, event, params);
}
int DialogCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
HILOG_INFO("Ace DialogCallbackStub::%{public}s, cmd = %{public}d, flags= %{public}d, code=%{public}d",
__func__, code, option.GetFlags(), code);
std::u16string descriptor = DialogCallbackStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
HILOG_INFO("local descriptor is not equal to remote");
return ERR_INVALID_STATE;
}
if (code == IDialogCallback::UI_SERVICE_DIALOG_CALLBACK) {
return OnDialogCallBackInner(data, reply);
}
HILOG_WARN("Ace %{public}s, default case, need check.", __func__);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int DialogCallbackStub::OnDialogCallBackInner(MessageParcel& data, MessageParcel& reply)
{
int32_t id = data.ReadInt32();
const std::string& event = data.ReadString();
const std::string& params = data.ReadString();
OnDialogCallback(id, event, params);
return ERR_NONE;
}
void DialogCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOG_ERROR("recv DialogCallbackRecipient death notice");
if (handler_) {
handler_(remote);
}
}
DialogCallbackRecipient::DialogCallbackRecipient(RemoteDiedHandler handler) : handler_(handler)
{}
DialogCallbackRecipient::~DialogCallbackRecipient()
{}
} // namespace Ace
} // namespace OHOS

View File

@ -16,24 +16,19 @@
#include "ui_mgr_service.h"
#include <atomic>
#include <unistd.h>
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "securec.h"
#include "string_ex.h"
#include "system_ability_definition.h"
#include "ui_service_mgr_errors.h"
#include "uiservice_dialog/uiservice_dialog_impl.h"
#include "uiservice_dialog/uiservice_dialog_proxy.h"
namespace OHOS {
namespace Ace {
namespace {
constexpr int32_t UI_MGR_SERVICE_SA_ID = 7001;
constexpr uint32_t UI_SERVICE_FLOGS = 0x10;
const bool REGISTER_RESULT =
SystemAbility::MakeAndRegisterAbility(DelayedSingleton<UIMgrService>::GetInstance().get());
}
@ -54,218 +49,9 @@ UIMgrService::~UIMgrService()
callbackMap_.clear();
}
static std::atomic<int32_t> gDialogId = 0;
AppSpawnMsg* UIMgrService::MakeAppSpawnMsg(const std::string& name, int32_t id)
{
size_t msgSize = sizeof(AppSpawnMsg) + 1;
AppSpawnMsg* msg = static_cast<AppSpawnMsg *>(malloc(msgSize));
if (msg == nullptr) {
HILOG_ERROR("Ace uiservice failed to malloc!");
return nullptr;
}
if (memset_s(msg, msgSize, 0, msgSize) != EOK) {
HILOG_ERROR("Ace uiservice failed to memset!");
return nullptr;
}
msg->uid = getuid();
msg->gid = getgid();
msg->accessTokenId = IPCSkeleton::GetCallingTokenID();
std::string proccessName = name + std::to_string(id);
if (strcpy_s(msg->processName, sizeof(msg->processName), proccessName.c_str()) != EOK) {
HILOG_ERROR("failed to copy proccess name!");
return nullptr;
}
msg->code = AppOperateType::DEFAULT;
msg->flags = UI_SERVICE_FLOGS;
return msg;
}
int32_t UIMgrService::AttachToUiService(const sptr<IRemoteObject>& dialog, int32_t pid)
{
HILOG_INFO("Ace uiservice AttachToUiService pid: %{public}d", pid);
if (dialog == nullptr) {
HILOG_ERROR("Ace dialog is nullptr");
}
auto dialogProxy = iface_cast<OHOS::Ace::IUiServiceDialog>(dialog);
if (dialogProxy == nullptr) {
HILOG_ERROR("Ace dialogProxy is nullptr");
return -1;
}
if (handler_ == nullptr) {
HILOG_ERROR("Ace uiservice Show dialog failed! handler is nullptr");
return UI_SERVICE_HANDLER_IS_NULL;
}
auto attachFunc = [ pid, dialogProxy, this ] () {
dialogMap_.emplace(pid, dialogProxy);
auto iter = dialogRecords_.find(pid);
if (iter == dialogRecords_.end()) {
HILOG_ERROR("Ace no dialog record: %{public}d", pid);
return;
}
auto dialogRecord = iter->second;
dialogProxy->ShowDialog(
dialogRecord.name, dialogRecord.params, dialogRecord.windowType,
dialogRecord.x, dialogRecord.y, dialogRecord.width, dialogRecord.height,
dialogRecord.id);
};
if (!handler_->PostSyncTask(attachFunc)) {
HILOG_ERROR("Post sync task error");
return UI_SERVICE_POST_TASK_FAILED;
}
return NO_ERROR;
}
int UIMgrService::ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id)
{
if (OpenAppSpawnConnection() != 0) {
HILOG_ERROR("Ace ShowDialog ui service failed to open app spawn connection.");
return UI_SERVICE_HANDLER_IS_NULL;
}
HILOG_INFO("Ace uiservice Show dialog name: %{public}s in service start %{public}s", name.c_str(), params.c_str());
if (handler_ == nullptr) {
HILOG_ERROR("Ace uiservice Show dialog failed! handler is nullptr");
return UI_SERVICE_HANDLER_IS_NULL;
}
int32_t dialogId = gDialogId.fetch_add(1, std::memory_order_relaxed);
if (id != nullptr) {
*id = dialogId;
}
HILOG_INFO("Ace uiservice Show dialog id: %{public}d", dialogId);
DialogParam dialogParams = {
name, params, static_cast<uint32_t>(windowType), x, y, width, height, dialogId };
auto showDialogFunc = [dialogId, &name, &dialogParams, dialogCallback, this] () {
AppSpawnMsg* message = MakeAppSpawnMsg(name, dialogId);
AppSpawnPidMsg pidMsg;
auto result = clientSocket_->WriteSocketMessage(message, sizeof(AppSpawnMsg));
if (result != sizeof(AppSpawnMsg)) {
HILOG_ERROR("Ace uiservice WriteMessage failed!");
return;
}
result = clientSocket_->ReadSocketMessage(reinterpret_cast<void *>(pidMsg.pidBuf), sizeof(pid_t));
if (result != sizeof(pid_t)) {
HILOG_ERROR("Ace uiservice ReadMessage failed!");
return;
}
HILOG_INFO("Ace uiservice id: %{public}d", pidMsg.pid);
dialogIDMap_.emplace(dialogId, pidMsg.pid);
dialogRecords_.emplace(pidMsg.pid, dialogParams);
dialogCallbackProxyMap_.emplace(dialogId, dialogCallback);
return;
};
if (!handler_->PostSyncTask(showDialogFunc)) {
HILOG_ERROR("Post sync task error");
return UI_SERVICE_POST_TASK_FAILED;
}
return NO_ERROR;
}
int UIMgrService::CancelDialog(int id)
{
HILOG_INFO("Ace CancelDialog id: %{public}d", id);
auto errorCode = UI_SERVICE_NO_ERROR;
if (handler_ == nullptr) {
HILOG_ERROR("Ace uiservice Show dialog failed! handler is nullptr");
return UI_SERVICE_HANDLER_IS_NULL;
}
auto cancelDialogFunc = [ id, this ] () {
auto pidIter = dialogIDMap_.find(id);
if (pidIter == dialogIDMap_.end()) {
HILOG_ERROR("Ace dialog id : %{public}d not found in pid map", id);
return;
}
int32_t pid = pidIter->second;
auto dialogIter = dialogMap_.find(pid);
if (dialogIter == dialogMap_.end()) {
HILOG_ERROR("Ace dialog pid : %{public}d not found in dialog map", pid);
return;
}
dialogIter->second->CancelDialog(id);
};
if (!handler_->PostSyncTask(cancelDialogFunc)) {
errorCode = UI_SERVICE_POST_TASK_FAILED;
}
HILOG_INFO("Ace uidialog cancel end");
return errorCode;
}
int UIMgrService::UpdateDialog(int id, const std::string& data)
{
HILOG_INFO("Ace UpdateDialog id: %{public}d", id);
auto errorCode = UI_SERVICE_NO_ERROR;
if (handler_ == nullptr) {
HILOG_ERROR("Ace uiservice Show dialog failed! handler is nullptr");
return UI_SERVICE_HANDLER_IS_NULL;
}
auto updateDialogFunc = [ id, data, this] () {
auto pidIter = dialogIDMap_.find(id);
if (pidIter == dialogIDMap_.end()) {
HILOG_ERROR("Ace dialog id : %{public}d not found in pid map", id);
return;
}
int32_t pid = pidIter->second;
auto dialogIter = dialogMap_.find(pid);
if (dialogIter == dialogMap_.end()) {
HILOG_ERROR("Ace dialog pid : %{public}d not found in dialog map", pid);
return;
}
dialogIter->second->UpdateDialog(id, data);
};
if (!handler_->PostSyncTask(updateDialogFunc)) {
errorCode = UI_SERVICE_POST_TASK_FAILED;
}
HILOG_INFO("Ace uidialog update end");
return errorCode;
}
int32_t UIMgrService::RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params)
{
HILOG_INFO("Ace RemoteDialogCallback id: %{public}d", id);
auto errorCode = UI_SERVICE_NO_ERROR;
if (handler_ == nullptr) {
HILOG_ERROR("Ace uiservice Show dialog failed! handler is nullptr");
return UI_SERVICE_HANDLER_IS_NULL;
}
auto remoteDialogCallback = [ id, event, params, this] () {
auto dialogProxyIter = dialogCallbackProxyMap_.find(id);
if (dialogProxyIter == dialogCallbackProxyMap_.end()) {
HILOG_ERROR("Ace no dialog proxy for id: %{public}d", id);
return;
}
dialogProxyIter->second->OnDialogCallback(id, event, params);
};
if (!handler_->PostSyncTask(remoteDialogCallback)) {
errorCode = UI_SERVICE_POST_TASK_FAILED;
}
HILOG_INFO("Ace uidialog RemoteDialogCallback end");
return errorCode;
}
int UIMgrService::Dump(int fd, const std::vector<std::u16string>& args)
int32_t UIMgrService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::lock_guard<std::mutex> lock(uiMutex_);
dprintf(fd, "total callbacks: %u\n", callbackMap_.size());
if (!callbackMap_.empty()) {
dprintf(fd, "callback keys: \n");
@ -302,38 +88,6 @@ void UIMgrService::OnStart()
HILOG_INFO("UIMgrService start success.");
}
int32_t UIMgrService::OpenAppSpawnConnection()
{
if (clientSocket_ == nullptr) {
clientSocket_ = std::make_shared<AppSpawn::ClientSocket>("AppSpawn");
if (clientSocket_ == nullptr) {
HILOG_ERROR("Ace ui service create app spawn socket client failed.");
return -1;
}
if (clientSocket_->CreateClient() != ERR_OK) {
HILOG_ERROR("Ace ui service failed to create socketClient");
return -1;
}
if (clientSocket_->ConnectSocket() != ERR_OK) {
HILOG_ERROR("Ace ui service failed to connect socket");
clientSocket_->CloseClient();
return -1;
}
HILOG_INFO("Ace ui service connection has been opened");
}
return 0;
}
void UIMgrService::CloseAppSpawnConnection()
{
if (clientSocket_ != nullptr) {
clientSocket_->CloseClient();
HILOG_INFO("Ace ui service connection has been closed");
return;
}
HILOG_INFO("Ace ui service app spawn socket client is null.");
}
bool UIMgrService::Init()
{
eventLoop_ = AppExecFwk::EventRunner::Create("UIMgrService");
@ -353,10 +107,10 @@ bool UIMgrService::Init()
void UIMgrService::OnStop()
{
HILOG_INFO("stop service");
eventLoop_->Stop();
eventLoop_.reset();
handler_.reset();
state_ = UIServiceRunningState::STATE_NOT_START;
CloseAppSpawnConnection();
}
UIServiceRunningState UIMgrService::QueryServiceState() const
@ -364,7 +118,7 @@ UIServiceRunningState UIMgrService::QueryServiceState() const
return state_;
}
int UIMgrService::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
int32_t UIMgrService::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
{
HILOG_INFO("UIMgrService::RegisterCallBack called start");
if (uiService == nullptr) {
@ -385,7 +139,7 @@ int UIMgrService::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIServic
return NO_ERROR;
}
int UIMgrService::UnregisterCallBack(const AAFwk::Want& want)
int32_t UIMgrService::UnregisterCallBack(const AAFwk::Want& want)
{
HILOG_INFO("UIMgrService::UnregisterCallBack called start");
if (handler_ == nullptr) {
@ -402,13 +156,12 @@ int UIMgrService::UnregisterCallBack(const AAFwk::Want& want)
return NO_ERROR;
}
int UIMgrService::Push(const AAFwk::Want& want, const std::string& name,
int32_t UIMgrService::Push(const AAFwk::Want& want, const std::string& name,
const std::string& jsonPath, const std::string& data, const std::string& extraData)
{
HILOG_INFO("UIMgrService::Push called start");
std::map<std::string, sptr<IUIService>>::iterator iter;
std::lock_guard<std::mutex> lock(uiMutex_);
for (iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
for (auto iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
sptr<IUIService> uiService = iter->second;
if (uiService == nullptr) {
return UI_SERVICE_IS_NULL;
@ -419,12 +172,11 @@ int UIMgrService::Push(const AAFwk::Want& want, const std::string& name,
return NO_ERROR;
}
int UIMgrService::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
int32_t UIMgrService::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
{
HILOG_INFO("UIMgrService::Request called start");
std::map<std::string, sptr<IUIService>>::iterator iter;
std::lock_guard<std::mutex> lock(uiMutex_);
for (iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
for (auto iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
sptr<IUIService> uiService = iter->second;
if (uiService == nullptr) {
return UI_SERVICE_IS_NULL;
@ -435,12 +187,12 @@ int UIMgrService::Request(const AAFwk::Want& want, const std::string& name, cons
return NO_ERROR;
}
int UIMgrService::ReturnRequest(
int32_t UIMgrService::ReturnRequest(
const AAFwk::Want& want, const std::string& source, const std::string& data, const std::string& extraData)
{
HILOG_INFO("UIMgrService::ReturnRequest called start");
std::map<std::string, sptr<IUIService>>::iterator iter;
for (iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
std::lock_guard<std::mutex> lock(uiMutex_);
for (auto iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) {
sptr<IUIService> uiService = iter->second;
if (uiService == nullptr) {
return UI_SERVICE_IS_NULL;
@ -450,12 +202,8 @@ int UIMgrService::ReturnRequest(
HILOG_INFO("UIMgrService::ReturnRequest called end");
return NO_ERROR;
}
std::shared_ptr<EventHandler> UIMgrService::GetEventHandler()
{
return handler_;
}
int UIMgrService::HandleRegister(const AAFwk::Want& want, const sptr<IUIService>& uiService)
int32_t UIMgrService::HandleRegister(const AAFwk::Want& want, const sptr<IUIService>& uiService)
{
HILOG_INFO("UIMgrService::HandleRegister called start");
std::lock_guard<std::mutex> lock(uiMutex_);
@ -470,7 +218,7 @@ int UIMgrService::HandleRegister(const AAFwk::Want& want, const sptr<IUIService>
return NO_ERROR;
}
int UIMgrService::HandleUnregister(const AAFwk::Want& want)
int32_t UIMgrService::HandleUnregister(const AAFwk::Want& want)
{
HILOG_INFO("UIMgrService::HandleUnregister called start");
std::lock_guard<std::mutex> lock(uiMutex_);
@ -498,6 +246,7 @@ std::string UIMgrService::GetCallBackKeyStr(const AAFwk::Want& want)
bool UIMgrService::CheckCallBackFromMap(const std::string& key)
{
HILOG_INFO("UIMgrService::CheckCallBackFromMap called start");
std::lock_guard<std::mutex> lock(uiMutex_);
auto it = callbackMap_.find(key);
if (it == callbackMap_.end()) {
return false;

View File

@ -15,7 +15,7 @@
#include "ui_service_mgr_client.h"
#include "dialog_callback_stub.h"
#include "dialog_callback.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
@ -23,29 +23,16 @@
#include "string_ex.h"
#include "system_ability_definition.h"
// external dependence
#include "ability_manager_client.h"
#include "display_manager.h"
namespace OHOS {
namespace Ace {
constexpr int UI_MGR_SERVICE_SA_ID = 7001;
constexpr int UI_DIALOG_PICKER_WIDTH = 519 * 2; // 519 vp
constexpr int UI_DIALOG_PICKER_HEIGHT = 256 * 2; // 256 vp
constexpr int UI_DIALOG_PICKER_WIDTH_NARROW = 360 * 2; // 360 vp
constexpr int UI_DIALOG_PICKER_HEIGHT_NARROW = 347 * 2; // 347 vp
constexpr int UI_DEFAULT_WIDTH = 2560;
constexpr int UI_DEFAULT_HEIGHT = 1600;
constexpr int UI_DEFAULT_BUTTOM_CLIP = 50 * 2; // 48vp
constexpr int UI_WIDTH_780DP = 780 * 2; // 780vp
constexpr int UI_HALF = 2;
constexpr int32_t UI_MGR_SERVICE_SA_ID = 7001;
std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::instance_ = nullptr;
std::mutex UIServiceMgrClient::mutex_;
std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::GetInstance()
{
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lock_l(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
if (instance_ == nullptr) {
instance_ = std::make_shared<UIServiceMgrClient>();
}
@ -53,11 +40,9 @@ std::shared_ptr<UIServiceMgrClient> UIServiceMgrClient::GetInstance()
return instance_;
}
UIServiceMgrClient::UIServiceMgrClient()
{}
UIServiceMgrClient::UIServiceMgrClient() = default;
UIServiceMgrClient::~UIServiceMgrClient()
{}
UIServiceMgrClient::~UIServiceMgrClient() =default;
ErrCode UIServiceMgrClient::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
{
@ -129,115 +114,27 @@ ErrCode UIServiceMgrClient::ReturnRequest(const AAFwk::Want& want, const std::st
ErrCode UIServiceMgrClient::ShowDialog(const std::string& name,
const std::string& params,
OHOS::Rosen::WindowType windowType,
int x,
int y,
int width,
int height,
int32_t x,
int32_t y,
int32_t width,
int32_t height,
DialogCallback callback,
int* id)
int32_t* id)
{
if (remoteObject_ == nullptr) {
ErrCode err = Connect();
if (err != ERR_OK) {
HILOG_ERROR("%{private}s:fail to connect UIMgrService", __func__);
return UI_SERVICE_NOT_CONNECTED;
}
}
const sptr<DialogCallbackStub> dialogCallbackStub(new (std::nothrow)DialogCallbackStub(callback));
sptr<IUIServiceMgr> doms = iface_cast<IUIServiceMgr>(remoteObject_);
if (doms == nullptr) {
HILOG_ERROR("doms is nullptr");
return UI_SERVICE_GET_PROXY_FAILED;
}
return doms->ShowDialog(
name, params, static_cast<uint32_t>(windowType), x, y, width, height, dialogCallbackStub, id);
HILOG_ERROR("Ui Service show dialog deprecated!");
return GET_UI_SERVICE_FAILED;
}
ErrCode UIServiceMgrClient::CancelDialog(int32_t id)
{
if (id < 0) {
HILOG_INFO("invalid parameter");
return UI_SERVICE_INVALID_PARAMETER;
}
if (remoteObject_ == nullptr) {
ErrCode err = Connect();
if (err != ERR_OK) {
HILOG_ERROR("%{private}s:fail to connect UIMgrService", __func__);
return UI_SERVICE_NOT_CONNECTED;
}
}
sptr<IUIServiceMgr> doms = iface_cast<IUIServiceMgr>(remoteObject_);
if (doms == nullptr) {
HILOG_ERROR("doms is nullptr");
return UI_SERVICE_GET_PROXY_FAILED;
}
return doms->CancelDialog(id);
HILOG_ERROR("Ui Service cancel dialog deprecated!");
return GET_UI_SERVICE_FAILED;
}
ErrCode UIServiceMgrClient::UpdateDialog(int32_t id, const std::string& data)
{
if (id < 0) {
HILOG_INFO("invalid parameter");
return UI_SERVICE_INVALID_PARAMETER;
}
if (remoteObject_ == nullptr) {
ErrCode err = Connect();
if (err != ERR_OK) {
HILOG_ERROR("%{private}s:fail to connect UIMgrService", __func__);
return UI_SERVICE_NOT_CONNECTED;
}
}
sptr<IUIServiceMgr> doms = iface_cast<IUIServiceMgr>(remoteObject_);
if (doms == nullptr) {
HILOG_ERROR("doms is nullptr");
return UI_SERVICE_GET_PROXY_FAILED;
}
return doms->UpdateDialog(id, data);
}
ErrCode UIServiceMgrClient::ShowAppPickerDialog(
const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, int32_t userId)
{
if (abilityInfos.size() == 0) {
HILOG_WARN("abilityInfos size is zero");
return UI_SERVICE_INVALID_PARAMETER;
}
int32_t offsetX = 0;
int32_t offsetY = 0;
int32_t width = UI_DIALOG_PICKER_WIDTH;
int32_t height = UI_DIALOG_PICKER_HEIGHT;
bool wideScreen = true;
GetDisplayPosition(offsetX, offsetY, width, height, wideScreen);
const std::string param = GetPickerDialogParam(want, abilityInfos, wideScreen);
HILOG_DEBUG("share dialog position:[%{public}d,%{public}d,%{public}d,%{public}d],str: %{public}s",
offsetX, offsetY, width, height, param.c_str());
const std::string jsBundleName = "dialog_picker_service";
return ShowDialog(jsBundleName, param, OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, offsetX, offsetY,
width, height, [want, userId](int32_t id, const std::string& event, const std::string& params) mutable {
HILOG_DEBUG("dialog callback: event: %{public}s, params: %{public}s", event.c_str(), params.c_str());
if (event == "SHARE_EVENT") {
std::string bundleName;
std::string abilityName;
auto pos = params.find(";");
if (pos != std::string::npos) {
bundleName = params.substr(0, pos);
abilityName = params.substr(pos + 1, params.length() - (pos + 1));
}
AAFwk::Want shareWant = want;
shareWant.SetAction("");
shareWant.SetElementName(bundleName, abilityName);
auto abilityClient = AAFwk::AbilityManagerClient::GetInstance();
if (abilityClient != nullptr) {
HILOG_INFO("dialog callback: %{public}s-%{public}s", bundleName.c_str(), abilityName.c_str());
abilityClient->StartAbility(shareWant, AAFwk::DEFAULT_INVAL_VALUE, userId);
}
}
Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
});
HILOG_ERROR("Ui Service update dialog deprecated!");
return GET_UI_SERVICE_FAILED;
}
/**
@ -264,86 +161,5 @@ ErrCode UIServiceMgrClient::Connect()
HILOG_DEBUG("connect UIMgrService success");
return ERR_OK;
}
const std::string UIServiceMgrClient::GetPickerDialogParam(
const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, bool wideScreen) const
{
auto type = want.GetStringParam("ability.picker.type");
auto text = want.GetStringParam("ability.picker.text");
auto uri = want.GetStringParam("ability.picker.uri");
auto fileNames = want.GetStringArrayParam("ability.picker.fileNames");
auto fileSizes = want.GetIntArrayParam("ability.picker.fileSizes");
std::string param = "{"; // json head
if (!wideScreen) {
param += "\"deviceType\": \"phone\",";
}
param += "\"previewCard\": { \"type\": \"";
param += type;
param += "\", \"icon\": \"";
param += "";
param += "\", \"mainText\": \"";
param += text;
param += "\", \"subText\": \"";
param += uri;
param += "\", \"fileList\": [";
for (int i = 0; i < (int)fileNames.size() && i < (int)fileSizes.size(); i++) {
param += "{";
param += "\"name\": \"";
param += fileNames[i];
param += "\", \"size\": ";
param += std::to_string(fileSizes[i]);
param += "}";
if (i != (int)fileNames.size() - 1 && i != (int)fileSizes.size() - 1) {
param += ",";
}
}
param += "]},";
param += "\"hapList\": [";
for (int i = 0; i < (int)abilityInfos.size(); i++) {
const auto& abilityInfo = abilityInfos[i];
param += "{ \"name\": \"";
param += std::to_string(abilityInfo.labelId); // or string abilityInfo.label
param += "\", \"icon\": \"";
param += std::to_string(abilityInfo.iconId); // or string abilityInfo.icon
param += "\", \"bundle\": \"";
param += abilityInfo.bundleName;
param += "\", \"ability\": \"";
param += abilityInfo.name;
param += "\" }";
if (i != (int)abilityInfos.size() - 1) {
param += ",";
}
}
param += "]";
param += "}"; // json tail
return param;
}
void UIServiceMgrClient::GetDisplayPosition(
int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen)
{
wideScreen = true;
auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
if (display == nullptr) {
HILOG_WARN("share dialog GetDefaultDisplay fail, try again.");
display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
}
if (display != nullptr) {
if (display->GetWidth() < UI_WIDTH_780DP) {
HILOG_INFO("share dialog narrow.");
wideScreen = false;
width = UI_DIALOG_PICKER_WIDTH_NARROW;
height = UI_DIALOG_PICKER_HEIGHT_NARROW;
}
offsetX = (display->GetWidth() - width) / UI_HALF;
offsetY = display->GetHeight() - height - UI_DEFAULT_BUTTOM_CLIP;
} else {
HILOG_WARN("share dialog get display fail, use default wide.");
offsetX = (UI_DEFAULT_WIDTH - width) / UI_HALF;
offsetY = UI_DEFAULT_HEIGHT - height - UI_DEFAULT_BUTTOM_CLIP;
}
}
} // namespace Ace
} // namespace OHOS

View File

@ -31,7 +31,7 @@ bool UIServiceMgrProxy::WriteInterfaceToken(MessageParcel& data)
return true;
}
int UIServiceMgrProxy::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
int32_t UIServiceMgrProxy::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
{
MessageParcel data;
MessageParcel reply;
@ -51,7 +51,7 @@ int UIServiceMgrProxy::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIS
HILOG_ERROR("register callback fail, uiService error");
return ERR_INVALID_VALUE;
}
int error = Remote()->SendRequest(IUIServiceMgr::REGISTER_CALLBACK, data, reply, option);
int32_t error = Remote()->SendRequest(IUIServiceMgr::REGISTER_CALLBACK, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("register callback fail, error: %d", error);
return error;
@ -59,7 +59,7 @@ int UIServiceMgrProxy::RegisterCallBack(const AAFwk::Want& want, const sptr<IUIS
return reply.ReadInt32();
}
int UIServiceMgrProxy::UnregisterCallBack(const AAFwk::Want& want)
int32_t UIServiceMgrProxy::UnregisterCallBack(const AAFwk::Want& want)
{
MessageParcel data;
MessageParcel reply;
@ -69,7 +69,7 @@ int UIServiceMgrProxy::UnregisterCallBack(const AAFwk::Want& want)
return UI_SERVICE_PROXY_INNER_ERR;
}
data.WriteParcelable(&want);
int error = Remote()->SendRequest(IUIServiceMgr::UNREGISTER_CALLBACK, data, reply, option);
int32_t error = Remote()->SendRequest(IUIServiceMgr::UNREGISTER_CALLBACK, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("unregister callback fail, error: %d", error);
return error;
@ -77,7 +77,7 @@ int UIServiceMgrProxy::UnregisterCallBack(const AAFwk::Want& want)
return reply.ReadInt32();
}
int UIServiceMgrProxy::Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
int32_t UIServiceMgrProxy::Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
const std::string& data, const std::string& extraData)
{
MessageParcel dataParcel;
@ -103,7 +103,7 @@ int UIServiceMgrProxy::Push(const AAFwk::Want& want, const std::string& name, co
HILOG_ERROR("fail to WriteString extraData");
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUIServiceMgr::PUSH, dataParcel, reply, option);
int32_t error = Remote()->SendRequest(IUIServiceMgr::PUSH, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Push fail, error: %d", error);
return error;
@ -111,7 +111,7 @@ int UIServiceMgrProxy::Push(const AAFwk::Want& want, const std::string& name, co
return reply.ReadInt32();
}
int UIServiceMgrProxy::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
int32_t UIServiceMgrProxy::Request(const AAFwk::Want& want, const std::string& name, const std::string& data)
{
MessageParcel dataParcel;
MessageParcel reply;
@ -132,7 +132,7 @@ int UIServiceMgrProxy::Request(const AAFwk::Want& want, const std::string& name,
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUIServiceMgr::REQUEST, dataParcel, reply, option);
int32_t error = Remote()->SendRequest(IUIServiceMgr::REQUEST, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Request fail, error: %d", error);
return error;
@ -140,7 +140,7 @@ int UIServiceMgrProxy::Request(const AAFwk::Want& want, const std::string& name,
return reply.ReadInt32();
}
int UIServiceMgrProxy::ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
int32_t UIServiceMgrProxy::ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
const std::string& extraData)
{
MessageParcel dataParcel;
@ -165,189 +165,11 @@ int UIServiceMgrProxy::ReturnRequest(const AAFwk::Want& want, const std::string&
HILOG_ERROR("fail to WriteString extraData");
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUIServiceMgr::RETURN_REQUEST, dataParcel, reply, option);
int32_t error = Remote()->SendRequest(IUIServiceMgr::RETURN_REQUEST, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Request fail, error: %d", error);
return error;
}
return reply.ReadInt32();
}
int UIServiceMgrProxy::ShowDialog(const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(dataParcel)) {
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteString(name)) {
HILOG_ERROR("fail to WriteString name");
return INVALID_DATA;
}
if (!dataParcel.WriteString(params)) {
HILOG_ERROR("fail to WriteString params");
return INVALID_DATA;
}
if (!dataParcel.WriteUint32(windowType)) {
HILOG_ERROR("fail to WriteUInt32 windowType");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(x)) {
HILOG_ERROR("fail to WriteInt32 x");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(y)) {
HILOG_ERROR("fail to WriteInt32 y");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(width)) {
HILOG_ERROR("fail to WriteInt32 width");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(height)) {
HILOG_ERROR("fail to WriteInt32 height");
return INVALID_DATA;
}
if (dialogCallback == nullptr) {
HILOG_ERROR("dialogCallback is nullptr");
return ERR_INVALID_VALUE;
}
if (!dataParcel.WriteRemoteObject(dialogCallback->AsObject())) {
HILOG_ERROR("dialogCallback error");
return ERR_INVALID_VALUE;
}
int error = Remote()->SendRequest(IUIServiceMgr::SHOW_DIALOG, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Request fail, error: %{public}d", error);
return error;
}
if (id != nullptr) {
*id = reply.ReadInt32();
}
return reply.ReadInt32();
}
int UIServiceMgrProxy::CancelDialog(int id)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(dataParcel)) {
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteInt32(id)) {
HILOG_ERROR("fail to WriteString id");
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUIServiceMgr::CANCEL_DIALOG, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Request fail, error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int UIServiceMgrProxy::UpdateDialog(int id, const std::string& data)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!WriteInterfaceToken(dataParcel)) {
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteInt32(id)) {
HILOG_ERROR("fail to WriteString id");
return INVALID_DATA;
}
if (!dataParcel.WriteString(data)) {
HILOG_ERROR("fail to WriteString data");
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUIServiceMgr::UPDATE_DIALOG, dataParcel, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Request fail, error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int32_t UIServiceMgrProxy::AttachToUiService(const sptr<IRemoteObject>& dialog, int32_t pid)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
if (!WriteInterfaceToken(dataParcel)) {
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteRemoteObject(dialog)) {
HILOG_ERROR("Failed to write remote object");
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteInt32(pid)) {
HILOG_ERROR("fail to WriteString pid");
return INVALID_DATA;
}
int32_t result = Remote()->SendRequest(IUIServiceMgr::ATTACH_DIALOG, dataParcel, reply, option);
if (result != NO_ERROR) {
HILOG_ERROR("Request fail, error: %{public}d", result);
return result;
}
return reply.ReadInt32();
}
int32_t UIServiceMgrProxy::RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
if (!WriteInterfaceToken(dataParcel)) {
return UI_SERVICE_PROXY_INNER_ERR;
}
if (!dataParcel.WriteInt32(id)) {
HILOG_ERROR("fail to WriteString pid");
return INVALID_DATA;
}
if (!dataParcel.WriteString(event)) {
HILOG_ERROR("fail to WriteString data");
return INVALID_DATA;
}
if (!dataParcel.WriteString(params)) {
HILOG_ERROR("fail to WriteString data");
return INVALID_DATA;
}
int32_t result = Remote()->SendRequest(IUIServiceMgr::REMOTE_DIALOG_CALLBACK, dataParcel, reply, option);
if (result != NO_ERROR) {
HILOG_ERROR("Request fail, error: %{public}d", result);
return result;
}
return reply.ReadInt32();
}
}

View File

@ -29,11 +29,6 @@ UIServiceMgrStub::UIServiceMgrStub()
requestFuncMap_[PUSH] = &UIServiceMgrStub::PushInner;
requestFuncMap_[REQUEST] = &UIServiceMgrStub::RequestInner;
requestFuncMap_[RETURN_REQUEST] = &UIServiceMgrStub::ReturnRequestInner;
requestFuncMap_[SHOW_DIALOG] = &UIServiceMgrStub::ShowDialogInner;
requestFuncMap_[CANCEL_DIALOG] = &UIServiceMgrStub::CancelDialogInner;
requestFuncMap_[UPDATE_DIALOG] = &UIServiceMgrStub::UpdateDialogInner;
requestFuncMap_[ATTACH_DIALOG] = &UIServiceMgrStub::AttachToUiServiceInner;
requestFuncMap_[REMOTE_DIALOG_CALLBACK] = &UIServiceMgrStub::RemoteDialogCallbackInner;
}
UIServiceMgrStub::~UIServiceMgrStub()
@ -41,7 +36,7 @@ UIServiceMgrStub::~UIServiceMgrStub()
requestFuncMap_.clear();
}
int UIServiceMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
int32_t UIServiceMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
HILOG_DEBUG("UIServiceMgrStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
@ -62,7 +57,7 @@ int UIServiceMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messag
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int UIServiceMgrStub::RegisterCallBackInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceMgrStub::RegisterCallBackInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -82,7 +77,7 @@ int UIServiceMgrStub::RegisterCallBackInner(MessageParcel& data, MessageParcel&
return NO_ERROR;
}
int UIServiceMgrStub::UnregisterCallBackInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceMgrStub::UnregisterCallBackInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -94,7 +89,7 @@ int UIServiceMgrStub::UnregisterCallBackInner(MessageParcel& data, MessageParcel
return NO_ERROR;
}
int UIServiceMgrStub::PushInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceMgrStub::PushInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -111,7 +106,7 @@ int UIServiceMgrStub::PushInner(MessageParcel& data, MessageParcel& reply)
return NO_ERROR;
}
int UIServiceMgrStub::RequestInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceMgrStub::RequestInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -125,7 +120,7 @@ int UIServiceMgrStub::RequestInner(MessageParcel& data, MessageParcel& reply)
return NO_ERROR;
}
int UIServiceMgrStub::ReturnRequestInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceMgrStub::ReturnRequestInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -139,62 +134,4 @@ int UIServiceMgrStub::ReturnRequestInner(MessageParcel& data, MessageParcel& rep
reply.WriteInt32(result);
return NO_ERROR;
}
int UIServiceMgrStub::ShowDialogInner(MessageParcel &data, MessageParcel &reply)
{
const std::string& name = data.ReadString();
const std::string& params = data.ReadString();
auto windowType = data.ReadUint32();
int x = data.ReadInt32();
int y = data.ReadInt32();
int width = data.ReadInt32();
int height = data.ReadInt32();
int id = 0;
auto object = data.ReadRemoteObject();
if (object == nullptr) {
HILOG_ERROR("ShowDialogInner read remote object failed");
return ERR_INVALID_VALUE;
}
auto dialogCallback = iface_cast<OHOS::Ace::IDialogCallback>(object);
int32_t result = ShowDialog(name, params, windowType, x, y, width, height, dialogCallback, &id);
reply.WriteInt32(id);
reply.WriteInt32(result);
return NO_ERROR;
}
int UIServiceMgrStub::CancelDialogInner(MessageParcel &data, MessageParcel &reply)
{
int32_t id = data.ReadInt32();
int32_t result = CancelDialog(id);
reply.WriteInt32(result);
return NO_ERROR;
}
int UIServiceMgrStub::UpdateDialogInner(MessageParcel &data, MessageParcel &reply)
{
int32_t id = data.ReadInt32();
std::string updateData = data.ReadString();
int32_t result = UpdateDialog(id, updateData);
reply.WriteInt32(result);
return NO_ERROR;
}
int32_t UIServiceMgrStub::AttachToUiServiceInner(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> client = data.ReadRemoteObject();
if (client == nullptr) {
HILOG_ERROR("AttachToUiServiceInner read remote object failed");
return -1;
}
int32_t pid = data.ReadInt32();
return AttachToUiService(client, pid);
}
int32_t UIServiceMgrStub::RemoteDialogCallbackInner(MessageParcel &data, MessageParcel &reply)
{
int32_t id = data.ReadInt32();
std::string event = data.ReadString();
std::string params = data.ReadString();
return RemoteDialogCallback(id, event, params);
}
}

View File

@ -63,7 +63,7 @@ void UIServiceProxy::OnPushCallBack(const AAFwk::Want& want, const std::string&
HILOG_ERROR("fail to WriteString extraData");
return;
}
int result = remote->SendRequest(IUIService::UI_SERVICE_PUSH_CALL_BACK, dataParcel, reply, option);
int32_t result = remote->SendRequest(IUIService::UI_SERVICE_PUSH_CALL_BACK, dataParcel, reply, option);
if (result == ERR_NONE) {
HILOG_INFO("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
return;
@ -101,7 +101,7 @@ void UIServiceProxy::OnRequestCallBack(const AAFwk::Want& want, const std::strin
HILOG_ERROR("fail to WriteString data");
return;
}
int result = remote->SendRequest(IUIService::UI_SERVICE_REQUEST_CALL_BACK, dataParcel, reply, option);
int32_t result = remote->SendRequest(IUIService::UI_SERVICE_REQUEST_CALL_BACK, dataParcel, reply, option);
if (result == ERR_NONE) {
HILOG_INFO("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
return;
@ -144,7 +144,7 @@ void UIServiceProxy::OnReturnRequest(
HILOG_ERROR("fail to WriteString extraData");
return;
}
int result = remote->SendRequest(IUIService::UI_SERVICE_RETURN_REQUEST, dataParcel, reply, option);
int32_t result = remote->SendRequest(IUIService::UI_SERVICE_RETURN_REQUEST, dataParcel, reply, option);
if (result == ERR_NONE) {
HILOG_INFO("%{public}s SendRequest ok, retval is %d", __func__, reply.ReadInt32());
return;

View File

@ -29,7 +29,7 @@ UIServiceStub::~UIServiceStub()
requestFuncMap_.clear();
}
int UIServiceStub::OnRemoteRequest(
int32_t UIServiceStub::OnRemoteRequest(
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
HILOG_DEBUG("UIServiceStub::%{public}s, cmd = %{public}d, flags= %{public}d, code=%{public}d",
@ -52,7 +52,7 @@ int UIServiceStub::OnRemoteRequest(
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int UIServiceStub::OnPushCallBackInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceStub::OnPushCallBackInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -67,7 +67,7 @@ int UIServiceStub::OnPushCallBackInner(MessageParcel& data, MessageParcel& reply
return ERR_NONE;
}
int UIServiceStub::OnReturnRequestInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceStub::OnReturnRequestInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -81,7 +81,7 @@ int UIServiceStub::OnReturnRequestInner(MessageParcel& data, MessageParcel& repl
return ERR_NONE;
}
int UIServiceStub::OnRequestCallBackInner(MessageParcel& data, MessageParcel& reply)
int32_t UIServiceStub::OnRequestCallBackInner(MessageParcel& data, MessageParcel& reply)
{
std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
@ -103,10 +103,8 @@ void UIServiceCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
}
}
UIServiceCallbackRecipient::UIServiceCallbackRecipient(RemoteDiedHandler handler) : handler_(handler)
{}
UIServiceCallbackRecipient::UIServiceCallbackRecipient(RemoteDiedHandler handler) : handler_(handler) {}
UIServiceCallbackRecipient::~UIServiceCallbackRecipient()
{}
UIServiceCallbackRecipient::~UIServiceCallbackRecipient() = default;
} // namespace Ace
} // namespace OHOS

View File

@ -16,7 +16,8 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#define private public
#define protected public
#include "mock_ui_service_stub.h"
#include "ui_mgr_service.h"
@ -71,7 +72,7 @@ HWTEST_F(UIMgrServiceTest, UIMgrServiceTest_GetEventHandler_0100, TestSize.Level
GTEST_LOG_(INFO) << "UIMgrServiceTest_GetEventHandler_0100 start";
auto uiMgrService = DelayedSingleton<UIMgrService>::GetInstance();
const std::shared_ptr<EventHandler> retVal = uiMgrService->GetEventHandler();
const std::shared_ptr<EventHandler> retVal = uiMgrService->handler_;
EXPECT_EQ(nullptr, retVal.get());
@ -92,7 +93,7 @@ HWTEST_F(UIMgrServiceTest, UIMgrServiceTest_OnStart_0100, TestSize.Level1)
uiMgrService->OnStart();
EXPECT_EQ(testValue, uiMgrService->QueryServiceState());
EXPECT_NE(nullptr, uiMgrService->GetEventHandler().get());
EXPECT_NE(nullptr, uiMgrService->handler_.get());
GTEST_LOG_(INFO) << "UIMgrServiceTest_OnStart_0100 end";
}
@ -207,7 +208,7 @@ HWTEST_F(UIMgrServiceTest, UIMgrServiceTest_OnStop_0100, TestSize.Level1)
uiMgrService->OnStop();
EXPECT_EQ(testValue, uiMgrService->QueryServiceState());
EXPECT_EQ(nullptr, uiMgrService->GetEventHandler().get());
EXPECT_EQ(nullptr, uiMgrService->handler_.get());
GTEST_LOG_(INFO) << "UIMgrServiceTest_OnStop_0100 end";
}

View File

@ -41,24 +41,6 @@ public:
MOCK_METHOD4(ReturnRequestCall, void(const AAFwk::Want& want, const std::string& source,
const std::string& data, const std::string& extraData));
MOCK_METHOD9(ShowDialog, int(const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id));
MOCK_METHOD1(CancelDialog, int(int id));
MOCK_METHOD2(UpdateDialog, int(int id, const std::string& data));
MOCK_METHOD2(AttachToUiService, int32_t(const sptr<IRemoteObject>& dialog, int32_t pid));
MOCK_METHOD3(RemoteDialogCallback, int32_t(int32_t id, const std::string& event, const std::string& params));
int RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService)
{
RegisterCallBackCall(want, uiService);

View File

@ -4,9 +4,7 @@
"path" : ["/system/bin/sa_main", "/system/profile/ui_service.xml"],
"uid" : "uiserver",
"gid" : ["system", "shell"],
"secon" : "u:r:ui_service:s0",
"apl" : "system_core",
"permission" : ["ohos.permisssion.REBOOT"]
"secon" : "u:r:ui_service:s0"
}
]
}

View File

@ -1,73 +0,0 @@
# Copyright (c) 2021-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.
import("//build/ohos.gni")
ace_root = "//foundation/arkui/ace_engine"
ace_engine_part = "ace_engine"
ace_engine_subsystem = "arkui"
config("uiservicedialog_config") {
include_dirs = [
"$ace_root/adapter/ohos/services/uiservice",
"$ace_root/adapter/ohos/services/uiservice/include",
"$ace_root/adapter/ohos/services/uiservice/uiservice_plugins",
"$ace_root/frameworks",
"$ace_root/interfaces/inner_api/ace",
]
}
ohos_source_set("uiservicedialog_sourceset_ohos") {
subsystem_name = ace_engine_subsystem
part_name = ace_engine_part
configs = [ ":uiservicedialog_config" ]
public_configs = configs
sources = [
"$ace_root/adapter/ohos/osal/log_wrapper.cpp",
"$ace_root/adapter/ohos/services/uiservice/uiservice_plugins/uiservice_dialog/uiservice_dialog_impl.cpp",
"$ace_root/adapter/ohos/services/uiservice/uiservice_plugins/uiservice_dialog/uiservice_dialog_proxy.cpp",
]
deps = [ "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr" ]
if (build_selinux) {
include_dirs = [
"//third_party/selinux/libselinux/include/",
"//base/security/selinux/interfaces/policycoreutils/include/",
]
deps += [
"//base/security/selinux:libload_policy",
"//base/security/selinux:librestorecon",
"//third_party/selinux:libselinux",
]
defines = [ "WITH_SELINUX" ]
}
external_deps = [
"ability_base:want",
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
}
ohos_shared_library("uiservicedialog") {
deps = [ ":uiservicedialog_sourceset_ohos" ]
public_deps = deps
part_name = ace_engine_part
subsystem_name = ace_engine_subsystem
}

View File

@ -1,322 +0,0 @@
/*
* 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 <dlfcn.h>
#include <unistd.h>
#include "ipc_skeleton.h"
#ifdef WITH_SELINUX
#include <policycoreutils.h>
#include <selinux/selinux.h>
#endif
#include "base/log/log.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "uiservice_dialog/uiservice_dialog_impl.h"
#include "uiservice_dialog/uiservice_dialog_proxy.h"
#include "ui_service_mgr_interface.h"
namespace OHOS::Ace {
namespace {
constexpr int32_t UI_MGR_SERVICE_SA_ID = 7001;
}
extern "C" ACE_FORCE_EXPORT void OHOS_ACE_InitDialog()
{
UiServiceDialogImpl::InitAceDialog();
}
sptr<UiServiceDialogImpl> UiServiceDialogImpl::nowDialog_;
UiServiceDialogImpl::UiServiceDialogImpl()
{
requestFuncMap_ = {
{ SHOW_DIALOG, &UiServiceDialogImpl::OnShowDialogRequest },
{ UPDATE_DIALOG, &UiServiceDialogImpl::OnUpdateDialogRequest },
{ CANCEL_DIALOG, &UiServiceDialogImpl::OnCancelDialogRequest },
};
}
UiServiceDialogImpl::~UiServiceDialogImpl()
{
ClearSharedLib();
}
void* UiServiceDialogImpl::OpenSharedLib(const char* libName)
{
void* handle = dlopen(libName, RTLD_LAZY);
if (handle == nullptr) {
LOGE("Failed to open %{public}s, error: %{public}s", libName, dlerror());
return nullptr;
}
return handle;
}
void* UiServiceDialogImpl::GetFunc(void* libHandle, const char* funName)
{
if (libHandle == nullptr) {
LOGE("lib is null, cannot cet func %{public}s", funName);
return nullptr;
}
void* func = dlsym(libHandle, funName);
if (func == nullptr) {
LOGE("Failed to get func %{public}s, error: %{public}s", funName, dlerror());
return nullptr;
}
return func;
}
int UiServiceDialogImpl::OnRemoteRequest(
uint32_t code,
MessageParcel &data,
MessageParcel &reply,
MessageOption &option)
{
LOGI("UiServiceDialogImpl::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
if (UiServiceDialogImpl::GetDescriptor() != data.ReadInterfaceToken()) {
LOGI("local descriptor is not equal to remote");
return -1;
}
auto itFunc = requestFuncMap_.find(code);
if (itFunc != requestFuncMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply);
}
}
LOGW("UiServiceDialogStub::OnRemoteRequest, default case, need check.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int32_t UiServiceDialogImpl::OnShowDialogRequest(MessageParcel& data, MessageParcel& reply)
{
LOGI("OnShowDialogRequest called.");
const std::string& name = data.ReadString();
const std::string& params = data.ReadString();
uint32_t windowType = data.ReadUint32();
int32_t x = data.ReadInt32();
int32_t y = data.ReadInt32();
int32_t width = data.ReadInt32();
int32_t height = data.ReadInt32();
int32_t id = data.ReadInt32();
int32_t result = ShowDialog(name, params, windowType, x, y, width, height, id);
reply.WriteInt32(result);
return result;
}
int32_t UiServiceDialogImpl::OnUpdateDialogRequest(MessageParcel &data, MessageParcel &reply)
{
LOGI("OnUpdateDialogRequest called.");
int32_t id = data.ReadInt32();
std::string updateData = data.ReadString();
int32_t result = UpdateDialog(id, updateData);
reply.WriteInt32(result);
return result;
}
int32_t UiServiceDialogImpl::OnCancelDialogRequest(MessageParcel& data, MessageParcel& reply)
{
int32_t id = data.ReadInt32();
int32_t result = CancelDialog(id);
reply.WriteInt32(result);
return result;
}
bool UiServiceDialogImpl::ClearSharedLib()
{
bool res = true;
if (dlclose(libHandle_) != 0) {
LOGE("Failed to close lib, error: %{public}s", dlerror());
res = false;
}
libHandle_ = nullptr;
return res;
}
void UiServiceDialogImpl::InitAceDialog()
{
LOGI("UiServiceDialogImpl Init begin");
#ifdef WITH_SELINUX
setcon("u:r:sa_dialog:s0");
#endif
nowDialog_ = new UiServiceDialogImpl();
nowDialog_->Init();
}
bool UiServiceDialogImpl::InitSharedLib()
{
constexpr char LIB_NAME[] = "libace.z.so";
constexpr char CREATE_DIALOG_FUNC[] = "OHOS_ACE_CreateDialog";
LOGI("UiServiceDialogImpl InitSharedLib");
libHandle_ = OpenSharedLib(LIB_NAME);
if (libHandle_ == nullptr) {
return false;
}
auto createFunc = reinterpret_cast<void* (*)()>(GetFunc(libHandle_, CREATE_DIALOG_FUNC));
if (createFunc == nullptr) {
LOGE("get create dialog func failed.");
ClearSharedLib();
return false;
}
uidialog_ = reinterpret_cast<UIDialogBase*>(createFunc());
if (uidialog_ == nullptr) {
LOGE("create ui dialog failed.");
ClearSharedLib();
createFunc = nullptr;
return false;
}
return true;
}
void UiServiceDialogImpl::Init()
{
LOGI("UiServiceDialogImpl Init(): %{public}p", this);
if (!InitSharedLib()) {
return;
}
eventRunner_ = OHOS::AppExecFwk::EventRunner::GetMainEventRunner();
if (eventRunner_ == nullptr) {
LOGE("eventLoop create failed.");
return;
}
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(eventRunner_);
if (eventHandler_ == nullptr) {
LOGE("handler create failed.");
return;
}
sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemManager == nullptr) {
LOGE("fail to get Registry");
return;
}
auto uiMgrService = systemManager->GetSystemAbility(UI_MGR_SERVICE_SA_ID);
if (uiMgrService == nullptr) {
LOGE("fail to connect UIMgrService");
return;
}
sptr<IUIServiceMgr> uiServiceMgrProxy = iface_cast<IUIServiceMgr>(uiMgrService);
uiServiceMgrProxy->AttachToUiService(nowDialog_->AsObject(), getpid());
int32_t ret = eventRunner_->Run();
if (ret != ERR_OK) {
LOGE("run failed! reason: %{public}d", ret);
}
}
void UiServiceDialogImpl::RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params)
{
LOGI("UiServiceDialogImpl::RemoteDialogCallback id: %{public}d", id);
sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemManager == nullptr) {
LOGE("fail to get Registry");
return;
}
auto uiMgrService = systemManager->GetSystemAbility(UI_MGR_SERVICE_SA_ID);
if (uiMgrService == nullptr) {
LOGE("fail to connect UIMgrService");
return;
}
sptr<IUIServiceMgr> uiServiceMgrProxy = iface_cast<IUIServiceMgr>(uiMgrService);
uiServiceMgrProxy->RemoteDialogCallback(id, event, params);
}
int32_t UiServiceDialogImpl::ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
int32_t dialogId)
{
LOGI("UiServiceDialogImpl Show Dialog id: %{public}d", dialogId);
if (eventHandler_ == nullptr) {
LOGE("UiServiceDialogImpl eventHandler is null");
return -1;
}
if (uidialog_ == nullptr) {
LOGE("Ui dialog instance not initialized.");
return -1;
}
auto dialogCallback = std::bind(
&UiServiceDialogImpl::RemoteDialogCallback, this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3);
auto func = [ uidialog = uidialog_, name, params, windowType, x, y, width, height, dialogCallback, dialogId ]() {
LOGI("UiServiceDialogImpl ShowDialog begin.");
uidialog->ShowDialog(name, params, windowType, x, y, width, height, dialogCallback, dialogId);
};
eventHandler_->PostSyncTask(func);
return 0;
}
int32_t UiServiceDialogImpl::CancelDialog(int32_t id)
{
LOGI("Ace cancel dialog id: %{public}d", id);
if (eventHandler_ == nullptr) {
LOGE("UiServiceDialogImpl eventHandler is null");
return -1;
}
if (uidialog_ == nullptr) {
LOGE("Ui dialog instance not initialized.");
return -1;
}
auto disableCallback = [ this ] () {
LOGI("stop uidialog");
eventRunner_->Stop();
eventHandler_.reset();
eventRunner_.reset();
};
auto func = [ uidialog = uidialog_, id, disableCallback ] () {
uidialog->CancelDialog(id, disableCallback);
};
eventHandler_->PostTask(func);
return 0;
}
int32_t UiServiceDialogImpl::UpdateDialog(int32_t id, const std::string& data)
{
LOGI("Ace update dialog id: %{public}d", id);
if (eventHandler_ == nullptr) {
LOGE("UiServiceDialogImpl eventHandler is null");
return -1;
}
if (uidialog_ == nullptr) {
LOGE("Ui dialog instance not initialized.");
return -1;
}
auto func = [ uidialog = uidialog_, id, data ] () {
uidialog->UpdateDialog(id, data);
};
eventHandler_->PostTask(func);
return 0;
}
}

View File

@ -1,81 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_UI_SERVICE_DIALOG_IMPL_H
#define OHOS_ACE_UI_SERVICE_DIALOG_IMPL_H
#include <memory>
#include <unordered_map>
#include <iremote_object.h>
#include <iremote_stub.h>
#include "event_handler.h"
#include "event_runner.h"
#include "nocopyable.h"
#include "base/utils/macros.h"
#include "uiservice_dialog_interface.h"
#include "ui_dialog_base.h"
namespace OHOS::Ace {
class ACE_FORCE_EXPORT UiServiceDialogImpl : public IRemoteStub<IUiServiceDialog> {
public:
UiServiceDialogImpl();
~UiServiceDialogImpl() override;
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
static void InitAceDialog();
int32_t ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
int32_t dialogId) override;
int32_t UpdateDialog(int32_t id, const std::string& data) override;
int32_t CancelDialog(int32_t id) override;
private:
static void* OpenSharedLib(const char* libName);
static void* GetFunc(void* libHandel, const char* funName);
void Init();
bool InitSharedLib();
bool ClearSharedLib();
void RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params);
int32_t OnShowDialogRequest(MessageParcel& data, MessageParcel& reply);
int32_t OnUpdateDialogRequest(MessageParcel& data, MessageParcel& reply);
int32_t OnCancelDialogRequest(MessageParcel& data, MessageParcel& reply);
using RequestFuncType = int32_t (UiServiceDialogImpl ::*)(MessageParcel& data, MessageParcel& reply);
std::unordered_map<uint32_t, RequestFuncType> requestFuncMap_;
std::shared_ptr<OHOS::AppExecFwk::EventRunner> eventRunner_;
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
void* libHandle_ = nullptr;
UIDialogBase* uidialog_ = nullptr;
static sptr<UiServiceDialogImpl> nowDialog_;
};
}
#endif

View File

@ -1,50 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_UISERVICE_DIALOG_INTERFACE_H
#define OHOS_ACE_UISERVICE_DIALOG_INTERFACE_H
#include <string>
#include "iremote_broker.h"
#include "base/utils/macros.h"
namespace OHOS::Ace {
class ACE_FORCE_EXPORT IUiServiceDialog : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ace.UiserviceDialog");
static constexpr int32_t SHOW_DIALOG = 0;
static constexpr int32_t UPDATE_DIALOG = 1;
static constexpr int32_t CANCEL_DIALOG = 2;
virtual int32_t ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
int32_t dialogId) = 0;
virtual int32_t UpdateDialog(int32_t dialogId, const std::string& data) = 0;
virtual int32_t CancelDialog(int32_t dialogId) = 0;
};
}
#endif

View File

@ -1,152 +0,0 @@
/*
* 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 "uiservice_dialog_proxy.h"
#include <iremote_object.h>
#include "base/log/log.h"
#include "message_parcel.h"
#include "string_ex.h"
namespace OHOS::Ace {
UiServiceDialogProxy::UiServiceDialogProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IUiServiceDialog>(impl) {}
UiServiceDialogProxy::~UiServiceDialogProxy() = default;
bool UiServiceDialogProxy::WriteInterfaceToken(MessageParcel& data)
{
if (!data.WriteInterfaceToken(IUiServiceDialog::GetDescriptor())) {
LOGE("write interface token failed");
return false;
}
return true;
}
int32_t UiServiceDialogProxy::ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
int32_t dialogId)
{
LOGI("UiServiceDialogProxy Show Dialog Begin");
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(dataParcel)) {
return -1;
}
if (!dataParcel.WriteString(name)) {
LOGE("fail to WriteString name");
return INVALID_DATA;
}
if (!dataParcel.WriteString(params)) {
LOGE("fail to WriteString params");
return INVALID_DATA;
}
if (!dataParcel.WriteUint32(windowType)) {
LOGE("fail to WriteUInt32 windowType");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(x)) {
LOGE("fail to WriteInt32 x");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(y)) {
LOGE("fail to WriteInt32 y");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(width)) {
LOGE("fail to WriteInt32 width");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(height)) {
LOGE("fail to WriteInt32 height");
return INVALID_DATA;
}
if (!dataParcel.WriteInt32(dialogId)) {
LOGE("fail to WriteInt32 height");
return INVALID_DATA;
}
int error = Remote()->SendRequest(IUiServiceDialog::SHOW_DIALOG, dataParcel, reply, option);
if (error != 0) {
LOGE("Request fail, error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int32_t UiServiceDialogProxy::UpdateDialog(int32_t dialogId, const std::string& data)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(dataParcel)) {
return -1;
}
if (!dataParcel.WriteInt32(dialogId)) {
LOGE("fail to WriteString id");
return -1;
}
if (!dataParcel.WriteString(data)) {
LOGE("fail to WriteString data");
return -1;
}
int error = Remote()->SendRequest(IUiServiceDialog::UPDATE_DIALOG, dataParcel, reply, option);
if (error != 0) {
LOGE("Request fail, error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
int32_t UiServiceDialogProxy::CancelDialog(int32_t dialogId)
{
MessageParcel dataParcel;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(dataParcel)) {
return -1;
}
if (!dataParcel.WriteInt32(dialogId)) {
LOGE("fail to WriteString id");
return -1;
}
int error = Remote()->SendRequest(IUiServiceDialog::CANCEL_DIALOG, dataParcel, reply, option);
if (error != 0) {
LOGE("Request fail, error: %{public}d", error);
return error;
}
return reply.ReadInt32();
}
}

View File

@ -1,48 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_UI_SERVICE_DIALOG_PROXY_H
#define OHOS_ACE_UI_SERVICE_DIALOG_PROXY_H
#include "iremote_proxy.h"
#include "base/utils/macros.h"
#include "uiservice_dialog_interface.h"
namespace OHOS::Ace {
class ACE_FORCE_EXPORT UiServiceDialogProxy : public IRemoteProxy<IUiServiceDialog> {
public:
explicit UiServiceDialogProxy(const sptr<IRemoteObject>& impl);
~UiServiceDialogProxy() override;
int32_t ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
int32_t dialogId) override;
int32_t UpdateDialog(int32_t dialogId, const std::string& data) override;
int32_t CancelDialog(int32_t dialogId) override;
private:
bool WriteInterfaceToken(MessageParcel& data);
static inline BrokerDelegator<UiServiceDialogProxy> delegator_;
};
}
#endif

View File

@ -16,5 +16,4 @@ uiservice_files = [
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_mgr_stub.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_proxy.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/dialog_callback_proxy.cpp",
]

View File

@ -1,52 +0,0 @@
/*
* 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.
*/
#ifndef OHOS_ACE_UI_DIALOG_BASE_H
#define OHOS_ACE_UI_DIALOG_BASE_H
#include <functional>
#include <string>
#include "refbase.h"
namespace OHOS::Ace {
class IDialogCallback;
class UIDialogBase {
public:
UIDialogBase() = default;
virtual ~UIDialogBase() = default;
// show system dialog
virtual void ShowDialog(
const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const std::function<void(int32_t, const std::string&, const std::string&)>& dialogCallback,
int32_t dialogId) = 0;
// update system dialog
virtual void UpdateDialog(int id, const std::string& data) = 0;
// cancel system dialog
virtual void CancelDialog(int32_t id, const std::function<void()>& destroyCallback) = 0;
};
}
#endif

View File

@ -18,6 +18,7 @@ import("//foundation/arkui/ace_engine/ace_config.gni")
config("uiservice_manager_public_config") {
visibility = [ ":*" ]
include_dirs = [
"$ace_root/frameworks",
"include/",
"//drivers/peripheral/base",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client/core",
@ -29,10 +30,6 @@ config("uiservice_manager_public_config") {
"$ability_runtime_innerkits_path/ability_manager/include/",
"$ability_runtime_path/interfaces/kits/native/ability/native",
"$ability_runtime_services_path/uiservicemgr/include",
"//third_party/icu/icu4c/source/common",
"//third_party/icu/icu4c/source/i18n",
"//third_party/icu/icu4c/source/ohos",
"//third_party/icu/icu4c/source",
"//commonlibrary/c_utils/base/include",
"//utils/system/safwk/native/include",
]
@ -44,15 +41,16 @@ config("uiservice_manager_public_config") {
ohos_shared_library("ui_service_mgr") {
sources = [
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/dialog_callback_proxy.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/dialog_callback_stub.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_mgr_client.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_mgr_proxy.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_proxy.cpp",
"//foundation/arkui/ace_engine/adapter/ohos/services/uiservice/src/ui_service_stub.cpp",
]
configs = [ "//commonlibrary/c_utils/base:utils_config" ]
configs = [
"$ace_root:ace_config",
"//commonlibrary/c_utils/base:utils_config",
]
public_configs = [
":uiservice_manager_public_config",
@ -63,13 +61,10 @@ ohos_shared_library("ui_service_mgr") {
external_deps = [
"ability_base:want",
"ability_runtime:ability_manager",
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_core",
"window_manager:libdm",
]
subsystem_name = ace_engine_subsystem

View File

@ -18,9 +18,11 @@
#include <iremote_broker.h>
#include "want.h"
#include "base/utils/macros.h"
namespace OHOS {
namespace Ace {
class IUIService : public OHOS::IRemoteBroker {
class ACE_FORCE_EXPORT IUIService : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ace.UIService");
@ -31,8 +33,8 @@ public:
};
IUIService() = default;
virtual ~IUIService() = default;
~IUIService() override = default;
/**
* @brief Called back to OnPush
*

View File

@ -18,21 +18,21 @@
#include <mutex>
#include "ability_info.h"
#include "iremote_object.h"
#include "dialog_callback_interface.h"
#include "dialog_callback.h"
#include "ui_service_interface.h"
#include "ui_service_mgr_errors.h"
#include "ui_service_mgr_interface.h"
#include "uri.h"
#include "wm_common.h"
#include "base/utils/macros.h"
namespace OHOS::Ace {
/**
* @class UIServiceMgrClient
* UIServiceMgrClient is used to access UIService manager services.
*/
class UIServiceMgrClient {
class ACE_FORCE_EXPORT UIServiceMgrClient {
public:
UIServiceMgrClient();
virtual ~UIServiceMgrClient();
@ -53,20 +53,17 @@ public:
ErrCode ShowDialog(const std::string& name,
const std::string& params,
OHOS::Rosen::WindowType windowType,
int x,
int y,
int width,
int height,
int32_t x,
int32_t y,
int32_t width,
int32_t height,
DialogCallback callback,
int* id = nullptr);
int32_t* id = nullptr);
ErrCode CancelDialog(int32_t id);
ErrCode UpdateDialog(int32_t id, const std::string& data);
ErrCode ShowAppPickerDialog(
const AAFwk::Want& want, const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, int32_t userId);
private:
/**
* Connect UIService manager service.
@ -75,11 +72,6 @@ private:
*/
ErrCode Connect();
const std::string GetPickerDialogParam(const AAFwk::Want& want,
const std::vector<AppExecFwk::AbilityInfo>& abilityInfos, bool wideScreen = true) const;
void GetDisplayPosition(
int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height, bool& wideScreen);
static std::mutex mutex_;
static std::shared_ptr<UIServiceMgrClient> instance_;
sptr<IRemoteObject> remoteObject_;

View File

@ -39,10 +39,6 @@ enum UiServiceErrorCode {
UI_SERVICE_HANDLER_IS_NULL,
UI_SERVICE_POST_TASK_FAILED,
NO_CALLBACK_FOR_KEY,
UI_SERVICE_INVALID_PARAMETER,
UI_SERVICE_GET_PROXY_FAILED,
UI_SERVICE_CREATE_WINDOW_FAILED,
UI_SERVICE_SHAERD_LIB_ERROR,
};
} // namespace Ace
} // namespace OHOS

View File

@ -21,55 +21,35 @@
#include <ipc_types.h>
#include <iremote_broker.h>
#include "dialog_callback_interface.h"
#include "ui_service_interface.h"
#include "uri.h"
#include "base/utils/macros.h"
namespace OHOS {
namespace Ace {
using Uri = OHOS::Uri;
const std::string UI_MANAGER_SERVICE_NAME = "UIMgrService";
/**
* @class IUIServiceMgr
* IUIServiceMgr interface is used to access UIService manager services.
*/
class IUIServiceMgr : public OHOS::IRemoteBroker {
class ACE_FORCE_EXPORT IUIServiceMgr : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ace.UIServiceMgr")
IUIServiceMgr() = default;
virtual ~IUIServiceMgr() = default;
~IUIServiceMgr() override = default;
virtual int RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) = 0;
virtual int32_t RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) = 0;
virtual int UnregisterCallBack(const AAFwk::Want& want) = 0;
virtual int32_t UnregisterCallBack(const AAFwk::Want& want) = 0;
virtual int Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
virtual int32_t Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
const std::string& data, const std::string& extraData) = 0;
virtual int Request(const AAFwk::Want& want, const std::string& name, const std::string& data) = 0;
virtual int32_t Request(const AAFwk::Want& want, const std::string& name, const std::string& data) = 0;
virtual int ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
virtual int32_t ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
const std::string& extraData) = 0;
virtual int ShowDialog(const std::string& name,
const std::string& params,
uint32_t windowType,
int x,
int y,
int width,
int height,
const sptr<OHOS::Ace::IDialogCallback>& dialogCallback,
int* id = nullptr) = 0;
virtual int CancelDialog(int id) = 0;
virtual int UpdateDialog(int id, const std::string& data) = 0;
virtual int32_t AttachToUiService(const sptr<IRemoteObject>& dialog, int32_t pid) = 0;
virtual int32_t RemoteDialogCallback(int32_t id, const std::string& event, const std::string& params) = 0;
enum {
// ipc id 1-1000 for kit
// ipc id for RegisterCallBack (1)
@ -79,11 +59,6 @@ public:
PUSH,
REQUEST,
RETURN_REQUEST,
SHOW_DIALOG,
CANCEL_DIALOG,
UPDATE_DIALOG,
ATTACH_DIALOG,
REMOTE_DIALOG_CALLBACK,
};
};
} // namespace Ace

View File

@ -24,21 +24,21 @@
#include <iremote_object.h>
#include <iremote_stub.h>
#include "base/utils/macros.h"
namespace OHOS {
namespace Ace {
class UIServiceStub : public IRemoteStub<IUIService> {
class ACE_FORCE_EXPORT UIServiceStub : public IRemoteStub<IUIService> {
public:
UIServiceStub();
virtual ~UIServiceStub();
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
~UIServiceStub() override;
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
private:
int OnRequestCallBackInner(MessageParcel& data, MessageParcel& reply);
int OnPushCallBackInner(MessageParcel& data, MessageParcel& reply);
int OnReturnRequestInner(MessageParcel& data, MessageParcel& reply);
using RequestFuncType = int (UIServiceStub::*)(MessageParcel& data, MessageParcel& reply);
int32_t OnRequestCallBackInner(MessageParcel& data, MessageParcel& reply);
int32_t OnPushCallBackInner(MessageParcel& data, MessageParcel& reply);
int32_t OnReturnRequestInner(MessageParcel& data, MessageParcel& reply);
using RequestFuncType = int32_t (UIServiceStub::*)(MessageParcel& data, MessageParcel& reply);
std::map<uint32_t, RequestFuncType> requestFuncMap_;
DISALLOW_COPY_AND_MOVE(UIServiceStub);
@ -52,8 +52,8 @@ class UIServiceCallbackRecipient : public IRemoteObject::DeathRecipient {
public:
using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject>&)>;
explicit UIServiceCallbackRecipient(RemoteDiedHandler handler);
virtual ~UIServiceCallbackRecipient();
virtual void OnRemoteDied(const wptr<IRemoteObject>& remote);
~UIServiceCallbackRecipient() override;
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
private:
RemoteDiedHandler handler_;

View File

@ -52,28 +52,6 @@ namespace OHOS {
OHOS::Ace::UIServiceMgrClient client;
return client.ReturnRequest(want, randomString, randomString, randomString) == ERR_OK;
}
bool CancelDialogTest(const uint8_t* data)
{
int32_t randomNumber = static_cast<int32_t>(U32_AT(data));
OHOS::Ace::UIServiceMgrClient client;
return client.CancelDialog(randomNumber) == ERR_OK;
}
bool UpdateDialogTest(const uint8_t* data)
{
std::string randomString = reinterpret_cast<const char*>(data);
int32_t randomNumber = static_cast<int32_t>(U32_AT(data));
OHOS::Ace::UIServiceMgrClient client;
return client.UpdateDialog(randomNumber, randomString) == ERR_OK;
}
bool ShowAppPickerDialogTest(const uint8_t* data, const AAFwk::Want& want)
{
std::vector<OHOS::AppExecFwk::AbilityInfo> abilityInfos;
OHOS::Ace::UIServiceMgrClient client;
return client.ShowAppPickerDialog(want, abilityInfos, static_cast<int32_t>(U32_AT(data))) == ERR_OK;
}
}
/* Fuzzer entry point */
@ -87,9 +65,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::PushTest(data, want);
OHOS::RequestTest(data, want);
OHOS::ReturnRequestTest(data, want);
OHOS::CancelDialogTest(data);
OHOS::UpdateDialogTest(data);
OHOS::ShowAppPickerDialogTest(data, want);
OHOS::UnregisterCallBackTest(data, want);
return 0;
}