Files
windowmanager/wmserver/src/window_manager_proxy.cpp
T
xingyanan dfc4bbc5da Merge branch 'master' of gitee.com:openharmony/windowmanager
Change-Id: I07ab471efda8ec57f16f338d5bcecf82efa11af7
Signed-off-by: xingyanan <xingyanan2@huawei.com>
2022-01-14 09:59:20 +08:00

425 lines
12 KiB
C++

/*
* Copyright (c) 2021 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 "window_manager_proxy.h"
#include <ipc_types.h>
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"};
}
WMError WindowManagerProxy::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteRemoteObject(window->AsObject())) {
WLOGFE("Write IWindow failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteParcelable(property.GetRefPtr())) {
WLOGFE("Write windowProperty failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteParcelable(surfaceNode.get())) {
WLOGFE("Write windowProperty failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_CREATE_WINDOW, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
windowId = reply.ReadUint32();
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::AddWindow(sptr<WindowProperty>& property)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteParcelable(property.GetRefPtr())) {
WLOGFE("Write windowProperty failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_ADD_WINDOW, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::RemoveWindow(uint32_t windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_REMOVE_WINDOW, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::DestroyWindow(uint32_t windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_DESTROY_WINDOW, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::MoveTo(uint32_t windowId, int32_t x, int32_t y)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteInt32(x)) {
WLOGFE("Write posX failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteInt32(y)) {
WLOGFE("Write posY failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_MOVE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::Resize(uint32_t windowId, uint32_t width, uint32_t height)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(width)) {
WLOGFE("Write width failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(height)) {
WLOGFE("Write height failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_RESIZE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::RequestFocus(uint32_t windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_REQUEST_FOCUS, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowMode(uint32_t windowId, WindowMode mode)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_MODE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowType(uint32_t windowId, WindowType type)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_TYPE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowFlags(uint32_t windowId, uint32_t flags)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(flags)) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_FLAGS, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) &&
data.WriteUint32(prop.contentColor_))) {
WLOGFE("Write property failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteRemoteObject(abilityToken)) {
WLOGFE("Write abilityToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_SEND_ABILITY_TOKEN, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
void WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
WMError WindowManagerProxy::MinimizeAllAppNodeAbility(uint32_t windowId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_MINIMIZE_ALL_APP_WINDOW, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
}
}