/* * 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. */ #include "zidl/window_manager_stub.h" #include #include #include #include #include "marshalling_helper.h" #include "memory_guard.h" #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerStub"}; } int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { MemoryGuard cacheGuard; if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return ERR_TRANSACTION_FAILED; } auto msgId = static_cast(code); switch (msgId) { case WindowManagerMessage::TRANS_ID_CREATE_WINDOW: { sptr windowObject = data.ReadRemoteObject(); sptr windowProxy = iface_cast(windowObject); sptr windowProperty = data.ReadStrongParcelable(); std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); uint32_t windowId; sptr token = nullptr; if (windowProperty && windowProperty->GetTokenState()) { token = data.ReadRemoteObject(); } WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId, token); reply.WriteUint32(windowId); reply.WriteInt32(static_cast(errCode)); if (windowProperty) { reply.WriteUint32(windowProperty->GetWindowFlags()); reply.WriteUint32(windowProperty->GetApiCompatibleVersion()); } break; } case WindowManagerMessage::TRANS_ID_ADD_WINDOW: { sptr windowProperty = data.ReadStrongParcelable(); WMError errCode = AddWindow(windowProperty); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_REMOVE_WINDOW: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_LIFE, "TRANS_ID_REMOVE_WINDOW Read windowId failed."); return ERR_INVALID_DATA; } bool isFromInnerkits = false; if (!data.ReadBool(isFromInnerkits)) { TLOGE(WmsLogTag::WMS_LIFE, "TRANS_ID_REMOVE_WINDOW Read isFromInnerkits failed."); return ERR_INVALID_DATA; } WMError errCode = RemoveWindow(windowId, isFromInnerkits); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_DESTROY_WINDOW: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_LIFE, "TRANS_ID_DESTROY_WINDOW Read windowId failed."); return ERR_INVALID_DATA; } WMError errCode = DestroyWindow(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_REQUEST_FOCUS: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_FOCUS, "read focus failed"); return ERR_INVALID_DATA; } WMError errCode = RequestFocus(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: { uint32_t windowId = data.ReadUint32(); uint32_t avoidAreaTypeId = 0; if (!data.ReadUint32(avoidAreaTypeId) || avoidAreaTypeId < static_cast(AvoidAreaType::TYPE_SYSTEM) || avoidAreaTypeId > static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR)) { return ERR_INVALID_DATA; } auto avoidAreaType = static_cast(avoidAreaTypeId); AvoidArea avoidArea = GetAvoidAreaByType(windowId, avoidAreaType); reply.WriteParcelable(&avoidArea); break; } case WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { uint32_t windowType = 0; if (!data.ReadUint32(windowType) || windowType >= static_cast(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) { return ERR_INVALID_DATA; } auto type = static_cast(windowType); sptr windowManagerAgentObject = data.ReadRemoteObject(); if (windowManagerAgentObject == nullptr) { return ERR_INVALID_DATA; } sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: { uint32_t windowType = 0; if (!data.ReadUint32(windowType) || windowType >= static_cast(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) { return ERR_INVALID_DATA; } auto type = static_cast(windowType); sptr windowManagerAgentObject = data.ReadRemoteObject(); if (windowManagerAgentObject == nullptr) { return ERR_INVALID_DATA; } sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { return ERR_INVALID_DATA; } sptr windowProperty = data.ReadStrongParcelable(); if (windowProperty == nullptr) { return ERR_INVALID_DATA; } sptr moveDragProperty = data.ReadStrongParcelable(); if (moveDragProperty == nullptr) { return ERR_INVALID_DATA; } NotifyServerReadyToMoveOrDrag(windowId, windowProperty, moveDragProperty); break; } case WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { return ERR_INVALID_DATA; } bool isPointDown = false; if (!data.ReadBool(isPointDown)) { return ERR_INVALID_DATA; } ProcessPointDown(windowId, isPointDown); break; } case WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { return ERR_INVALID_DATA; } ProcessPointUp(windowId); break; } case WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID: { uint32_t mainWinId = 0; if (!data.ReadUint32(mainWinId)) { TLOGE(WmsLogTag::WMS_HIERARCHY, "read mainWinId failed"); return ERR_INVALID_DATA; } uint32_t topWinId = 0; WMError errCode = GetTopWindowId(mainWinId, topWinId); reply.WriteUint32(topWinId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS: { uint64_t displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_LIFE, "Read displayID failed."); return ERR_INVALID_DATA; } WMError errCode = MinimizeAllAppWindows(displayId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS: { WMError errCode = ToggleShownStateForAllAppWindows(); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE: { uint32_t layoutMode = 0; if (!data.ReadUint32(layoutMode)) { TLOGE(WmsLogTag::WMS_LAYOUT, "read layoutMode failed"); return ERR_INVALID_DATA; } auto mode = static_cast(layoutMode); WMError errCode = SetWindowLayoutMode(mode); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY: { uint32_t actionValue = 0; if (!data.ReadUint32(actionValue)) { TLOGE(WmsLogTag::DEFAULT, "read action error"); return ERR_INVALID_DATA; } auto action = static_cast(actionValue); sptr windowProperty = new WindowProperty(); windowProperty->Read(data, action); WMError errCode = UpdateProperty(windowProperty, action); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID: { std::vector> infos; WMError errCode = GetAccessibilityWindowInfo(infos); if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, infos)) { WLOGFE("Write accessibility window infos failed"); return -1; } reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO_ID: { int32_t windowId = 0; if (!data.ReadInt32(windowId)) { WLOGFE("Failed to readInt32 windowId"); return ERR_INVALID_DATA; } std::vector> infos; WMError errCode = GetUnreliableWindowInfo(windowId, infos); if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, infos)) { WLOGFE("Write unreliable window infos failed"); return ERR_INVALID_DATA; } reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID: { std::vector> infos; WMError errCode = GetVisibilityWindowInfo(infos); if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, infos)) { WLOGFE("Write visibility window infos failed"); return -1; } reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER: { sptr controllerObject = data.ReadRemoteObject(); if (controllerObject == nullptr) { TLOGE(WmsLogTag::DEFAULT, "Read animation controller object failed"); return ERR_INVALID_DATA; } sptr controller = iface_cast(controllerObject); WMError errCode = SetWindowAnimationController(controller); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG: { SystemConfig config; WMError errCode = GetSystemConfig(config); reply.WriteParcelable(&config); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION: { sptr from = data.ReadParcelable(); sptr to = data.ReadParcelable(); bool isFromClient = false; if (!data.ReadBool(isFromClient)) { return ERR_INVALID_DATA; } WMError errCode = NotifyWindowTransition(from, to, isFromClient); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE: { DisplayId displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "read displayId failed"); return ERR_INVALID_DATA; } ModeChangeHotZones hotZones = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; WMError errCode = GetModeChangeHotZones(displayId, hotZones); reply.WriteInt32(static_cast(errCode)); reply.WriteInt32(hotZones.fullscreen_.posX_); reply.WriteInt32(hotZones.fullscreen_.posY_); reply.WriteUint32(hotZones.fullscreen_.width_); reply.WriteUint32(hotZones.fullscreen_.height_); reply.WriteInt32(hotZones.primary_.posX_); reply.WriteInt32(hotZones.primary_.posY_); reply.WriteUint32(hotZones.primary_.width_); reply.WriteUint32(hotZones.primary_.height_); reply.WriteInt32(hotZones.secondary_.posX_); reply.WriteInt32(hotZones.secondary_.posY_); reply.WriteUint32(hotZones.secondary_.width_); reply.WriteUint32(hotZones.secondary_.height_); break; } case WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK: { std::vector windowIds; data.ReadUInt32Vector(&windowIds); bool isAnimated = data.ReadBool(); sptr finishedCallback = nullptr; MinimizeWindowsByLauncher(windowIds, isAnimated, finishedCallback); if (finishedCallback == nullptr) { if (!reply.WriteBool(false)) { WLOGFE("finishedCallback is nullptr and failed to write!"); return ERR_INVALID_DATA; } } else { if (!reply.WriteBool(true) || !reply.WriteRemoteObject(finishedCallback->AsObject())) { WLOGFE("finishedCallback is not nullptr and failed to write!"); return ERR_INVALID_DATA; } } break; } case WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { return ERR_INVALID_DATA; } bool haveAvoidAreaListener = false; if (!data.ReadBool(haveAvoidAreaListener)) { return ERR_INVALID_DATA; } WMError errCode = UpdateAvoidAreaListener(windowId, haveAvoidAreaListener); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { return ERR_INVALID_DATA; } bool isAdd = false; if (!data.ReadBool(isAdd)) { return ERR_INVALID_DATA; } WMError errCode = UpdateRsTree(windowId, isAdd); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET: { uint32_t windowId = data.ReadUint32(); sptr targetToken = data.ReadRemoteObject(); if (targetToken == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "Read targetToken object failed!"); return ERR_INVALID_DATA; } WMError errCode = BindDialogTarget(windowId, targetToken); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE : { int32_t x = 0; int32_t y = 0; if (!data.ReadInt32(x) || !data.ReadInt32(y)) { return ERR_INVALID_DATA; } float scale = 0.0f; if (!data.ReadFloat(scale)) { return ERR_INVALID_DATA; } SetAnchorAndScale(x, y, scale); break; } case WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET: { int32_t deltaX = 0; int32_t deltaY = 0; if (!data.ReadInt32(deltaX) || !data.ReadInt32(deltaY)) { return ERR_INVALID_DATA; } SetAnchorOffset(deltaX, deltaY); break; } case WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM: { OffWindowZoom(); break; } case WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_HIERARCHY, "read windowId failed"); return ERR_INVALID_DATA; } WMError errCode = RaiseToAppTop(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_SNAPSHOT: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::DEFAULT, "read windowId error"); return ERR_INVALID_DATA; } std::shared_ptr pixelMap = GetSnapshot(windowId); reply.WriteParcelable(pixelMap.get()); break; } case WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED: { bool enable = data.ReadBool(); WMError errCode = SetGestureNavigationEnabled(enable); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY: { uint32_t windowId = INVALID_WINDOW_ID; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_KEYBOARD, "Read windowId failed."); return ERR_INVALID_DATA; } uint32_t gravityValue = 0; if (!data.ReadUint32(gravityValue) || gravityValue < static_cast(WindowGravity::WINDOW_GRAVITY_FLOAT) || gravityValue > static_cast(WindowGravity::WINDOW_GRAVITY_BOTTOM)) { TLOGE(WmsLogTag::WMS_KEYBOARD, "Window gravity value read failed, gravityValue: %{public}d", gravityValue); return ERR_INVALID_DATA; } WindowGravity gravity = static_cast(gravityValue); uint32_t percent = 0; if (!data.ReadUint32(percent)) { TLOGE(WmsLogTag::WMS_KEYBOARD, "Percent read failed."); return ERR_INVALID_DATA; } WMError errCode = SetWindowGravity(windowId, gravity, percent); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT: { uint32_t windowId = 0; if (!data.ReadUint32(windowId)) { TLOGE(WmsLogTag::WMS_EVENT, "Read failed!"); return ERR_INVALID_DATA; } std::shared_ptr event = MMI::KeyEvent::Create(); if (event == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "event is null"); return ERR_INVALID_DATA; } event->ReadFromParcel(data); DispatchKeyEvent(windowId, event); break; } case WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT: { std::vector info; if (!data.ReadStringVector(&info)) { return ERR_INVALID_DATA; } NotifyDumpInfoResult(info); break; } case WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS: { std::vector missionIds; if (!data.ReadUInt32Vector(&missionIds)) { TLOGE(WmsLogTag::DEFAULT, "Read animation target mission ids failed"); return ERR_INVALID_DATA; } std::vector> targets; WMError errCode = GetWindowAnimationTargets(missionIds, targets); if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, targets)) { WLOGFE("Write window animation targets failed"); return ERR_INVALID_DATA; } reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_SET_MAXIMIZE_MODE: { uint32_t modeId = 0; if (!data.ReadUint32(modeId) || modeId >= static_cast(MaximizeMode::MODE_END)) { return ERR_INVALID_DATA; } MaximizeMode maximizeMode = static_cast(modeId); SetMaximizeMode(maximizeMode); break; } case WindowManagerMessage::TRANS_ID_GET_MAXIMIZE_MODE: { MaximizeMode maximizeMode = GetMaximizeMode(); reply.WriteInt32(static_cast(maximizeMode)); break; } case WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO: { FocusChangeInfo focusInfo; GetFocusWindowInfo(focusInfo); reply.WriteParcelable(&focusInfo); break; } default: WLOGFW("unknown transaction code %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } return ERR_NONE; } } // namespace Rosen } // namespace OHOS