1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "zidl/window_manager_agent_stub.h"
17 #include "ipc_skeleton.h"
18 #include "marshalling_helper.h"
19 #include "window_manager_hilog.h"
20 #include "wm_common.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerAgentStub"};
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
29     MessageParcel& reply, MessageOption& option)
30 {
31     WLOGFD("code is %{public}u", code);
32     if (data.ReadInterfaceToken() != GetDescriptor()) {
33         WLOGFE("InterfaceToken check failed");
34         return ERR_TRANSACTION_FAILED;
35     }
36     WindowManagerAgentMsg msgId = static_cast<WindowManagerAgentMsg>(code);
37     switch (msgId) {
38         case WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS: {
39             sptr<FocusChangeInfo> info = data.ReadParcelable<FocusChangeInfo>();
40             if (info == nullptr) {
41                 WLOGFE("FocusChangeInfo is null");
42                 return ERR_INVALID_DATA;
43             }
44             bool focused = data.ReadBool();
45             UpdateFocusChangeInfo(info, focused);
46             break;
47         }
48         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE: {
49             WindowModeType type = static_cast<WindowModeType>(data.ReadUint8());
50             UpdateWindowModeTypeInfo(type);
51             break;
52         }
53         case WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: {
54             DisplayId displayId = data.ReadUint64();
55             SystemBarRegionTints tints;
56             bool res = MarshallingHelper::UnmarshallingVectorObj<SystemBarRegionTint>(data, tints,
57                 [](Parcel& parcel, SystemBarRegionTint& tint) {
58                     uint32_t type;
59                     SystemBarProperty prop;
60                     Rect region;
61                     bool res = parcel.ReadUint32(type) && parcel.ReadBool(prop.enable_) &&
62                         parcel.ReadUint32(prop.backgroundColor_) && parcel.ReadUint32(prop.contentColor_) &&
63                         parcel.ReadInt32(region.posX_) && parcel.ReadInt32(region.posY_) &&
64                         parcel.ReadUint32(region.width_) && parcel.ReadUint32(region.height_);
65                     tint.type_ = static_cast<WindowType>(type);
66                     tint.prop_ = prop;
67                     tint.region_ = region;
68                     return res;
69                 }
70             );
71             if (!res) {
72                 WLOGFE("fail to read SystemBarRegionTints.");
73                 break;
74             }
75             UpdateSystemBarRegionTints(displayId, tints);
76             break;
77         }
78         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS: {
79             std::vector<sptr<AccessibilityWindowInfo>> infos;
80             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
81                 WLOGFE("read accessibility window infos failed");
82                 return ERR_INVALID_DATA;
83             }
84             WindowUpdateType type = static_cast<WindowUpdateType>(data.ReadUint32());
85             NotifyAccessibilityWindowInfo(infos, type);
86             break;
87         }
88         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY: {
89             std::vector<sptr<WindowVisibilityInfo>> infos;
90             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(data, infos)) {
91                 WLOGFE("fail to read WindowVisibilityInfo.");
92                 break;
93             }
94             UpdateWindowVisibilityInfo(infos);
95             break;
96         }
97         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE: {
98             std::vector<sptr<WindowDrawingContentInfo>> infos;
99             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowDrawingContentInfo>(data, infos)) {
100                 WLOGFE("fail to read WindowDrawingContentInfo.");
101                 break;
102             }
103             UpdateWindowDrawingContentInfo(infos);
104             break;
105         }
106         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT: {
107             uint32_t accessTokenId = data.ReadUint32();
108             bool isShowing = data.ReadBool();
109             UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
110             break;
111         }
112         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG: {
113             bool showWaterMark = data.ReadBool();
114             NotifyWaterMarkFlagChangedResult(showWaterMark);
115             break;
116         }
117         case WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM: {
118             std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
119             bool res = MarshallingHelper::UnmarshallingVectorObj<VisibleWindowNumInfo>(
120                 data, visibleWindowNumInfo, [](Parcel& parcel, VisibleWindowNumInfo& num) {
121                     uint32_t displayId = -1;
122                     uint32_t visibleWindowNum = -1;
123                     bool res = parcel.ReadUint32(displayId) && parcel.ReadUint32(visibleWindowNum);
124                     num.displayId = displayId;
125                     num.visibleWindowNum = visibleWindowNum;
126                     return res;
127                 }
128             );
129             if (!res) {
130                 WLOGFE("fail to read VisibleWindowNumInfo.");
131                 break;
132             }
133             UpdateVisibleWindowNum(visibleWindowNumInfo);
134             break;
135         }
136         case WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED: {
137             bool enbale = data.ReadBool();
138             NotifyGestureNavigationEnabledResult(enbale);
139             break;
140         }
141         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
142             uint32_t accessTokenId = data.ReadUint32();
143             bool isShowing = data.ReadBool();
144             UpdateCameraWindowStatus(accessTokenId, isShowing);
145             break;
146         }
147         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE: {
148             WindowStyleType type = static_cast<WindowStyleType>(data.ReadUint8());
149             NotifyWindowStyleChange(type);
150             break;
151         }
152         case WindowManagerAgentMsg::TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED: {
153             std::string bundleName = data.ReadString();
154             bool isForeground = data.ReadBool();
155             UpdatePiPWindowStateChanged(bundleName, isForeground);
156             break;
157         }
158         default:
159             WLOGFW("unknown transaction code %{public}d", code);
160             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
161     }
162     return ERR_NONE;
163 }
164 } // namespace Rosen
165 } // namespace OHOS
166