/* * 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 #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"}; } WMError WindowManagerProxy::CreateWindow(sptr& window, sptr& property, const std::shared_ptr& 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(ret); } WMError WindowManagerProxy::AddWindow(sptr& 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(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(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(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(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(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(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(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(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(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(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(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(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(ret); } WMError WindowManagerProxy::SaveAbilityToken(const sptr& 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(ret); } void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return; } if (!data.WriteUint32(static_cast(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& windowManagerAgent) { MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return; } if (!data.WriteUint32(static_cast(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(ret); } } }