/* * 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(); } else { WLOGI("accept token is nullptr"); } 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 = data.ReadUint32(); bool isFromInnerkits = data.ReadBool(); WMError errCode = RemoveWindow(windowId, isFromInnerkits); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_DESTROY_WINDOW: { uint32_t windowId = data.ReadUint32(); WMError errCode = DestroyWindow(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_REQUEST_FOCUS: { uint32_t windowId = data.ReadUint32(); WMError errCode = RequestFocus(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: { uint32_t windowId = data.ReadUint32(); auto avoidAreaType = static_cast(data.ReadUint32()); AvoidArea avoidArea = GetAvoidAreaByType(windowId, avoidAreaType); reply.WriteParcelable(&avoidArea); break; } case WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { auto type = static_cast(data.ReadUint32()); sptr windowManagerAgentObject = data.ReadRemoteObject(); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: { auto type = static_cast(data.ReadUint32()); sptr windowManagerAgentObject = data.ReadRemoteObject(); 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 = data.ReadUint32(); sptr windowProperty = data.ReadStrongParcelable(); sptr moveDragProperty = data.ReadStrongParcelable(); NotifyServerReadyToMoveOrDrag(windowId, windowProperty, moveDragProperty); break; } case WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN: { uint32_t windowId = data.ReadUint32(); bool isPointDown = data.ReadBool(); ProcessPointDown(windowId, isPointDown); break; } case WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP: { uint32_t windowId = data.ReadUint32(); ProcessPointUp(windowId); break; } case WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID: { uint32_t mainWinId = data.ReadUint32(); uint32_t topWinId; WMError errCode = GetTopWindowId(mainWinId, topWinId); reply.WriteUint32(topWinId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS: { WMError errCode = MinimizeAllAppWindows(data.ReadUint64()); 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: { auto mode = static_cast(data.ReadUint32()); WMError errCode = SetWindowLayoutMode(mode); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY: { auto action = static_cast(data.ReadUint32()); 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(); 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 = data.ReadBool(); WMError errCode = NotifyWindowTransition(from, to, isFromClient); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE: { DisplayId displayId = data.ReadUint64(); 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 = data.ReadUint32(); bool haveAvoidAreaListener = data.ReadBool(); WMError errCode = UpdateAvoidAreaListener(windowId, haveAvoidAreaListener); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE: { uint32_t windowId = data.ReadUint32(); bool isAdd = data.ReadBool(); 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(); WMError errCode = BindDialogTarget(windowId, targetToken); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE : { int32_t x = data.ReadInt32(); int32_t y = data.ReadInt32(); float scale = data.ReadFloat(); SetAnchorAndScale(x, y, scale); break; } case WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET: { int32_t deltaX = data.ReadInt32(); int32_t deltaY = data.ReadInt32(); SetAnchorOffset(deltaX, deltaY); break; } case WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM: { OffWindowZoom(); break; } case WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER: { uint32_t windowId = data.ReadUint32(); WMError errCode = RaiseToAppTop(windowId); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_SNAPSHOT: { uint32_t windowId = data.ReadUint32(); std::shared_ptr pixelMap = GetSnapshot(windowId); reply.WriteParcelable(pixelMap.get()); break; } case WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED: { bool enable = data.ReadBool(); WMError errCode = SetGestureNavigaionEnabled(enable); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY: { uint32_t windowId = data.ReadUint32(); WindowGravity gravity = static_cast(data.ReadUint32()); uint32_t percent = data.ReadUint32(); WMError errCode = SetWindowGravity(windowId, gravity, percent); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT: { uint32_t windowId = data.ReadUint32(); std::shared_ptr event = MMI::KeyEvent::Create(); if (event == nullptr) { WLOGFE("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; data.ReadStringVector(&info); NotifyDumpInfoResult(info); break; } case WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS: { std::vector missionIds; data.ReadUInt32Vector(&missionIds); 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: { MaximizeMode maximizeMode = static_cast(data.ReadUint32()); 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