1 /*
2  * Copyright (c) 2021 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_proxy.h"
17 #include <ipc_types.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, "WindowManagerAgentProxy"};
26 }
27 
UpdateFocusChangeInfo(const sptr<FocusChangeInfo> & focusChangeInfo,bool focused)28 void WindowManagerAgentProxy::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused)
29 {
30     MessageParcel data;
31     if (focusChangeInfo == nullptr) {
32         WLOGFE("Invalid focus change info");
33         return;
34     }
35 
36     if (!data.WriteInterfaceToken(GetDescriptor())) {
37         WLOGFE("WriteInterfaceToken failed");
38         return;
39     }
40 
41     if (!data.WriteParcelable(focusChangeInfo)) {
42         WLOGFE("Write displayId failed");
43         return;
44     }
45 
46     if (!data.WriteBool(focused)) {
47         WLOGFE("Write Focus failed");
48         return;
49     }
50     MessageParcel reply;
51     MessageOption option(MessageOption::TF_ASYNC);
52     sptr<IRemoteObject> remote = Remote();
53     if (remote == nullptr) {
54         WLOGFE("remote is null");
55         return;
56     }
57     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS),
58         data, reply, option) != ERR_NONE) {
59         WLOGFE("SendRequest failed");
60     }
61 }
62 
UpdateWindowModeTypeInfo(WindowModeType type)63 void WindowManagerAgentProxy::UpdateWindowModeTypeInfo(WindowModeType type)
64 {
65     MessageParcel data;
66 
67     if (!data.WriteInterfaceToken(GetDescriptor())) {
68         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
69         return;
70     }
71 
72     if (!data.WriteUint8(static_cast<uint8_t>(type))) {
73         TLOGE(WmsLogTag::WMS_MAIN, "Write displayId failed");
74         return;
75     }
76 
77     MessageParcel reply;
78     MessageOption option(MessageOption::TF_ASYNC);
79     sptr<IRemoteObject> remote = Remote();
80     if (remote == nullptr) {
81         WLOGFE("remote is null");
82         return;
83     }
84     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE),
85         data, reply, option) != ERR_NONE) {
86         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
87     }
88 }
89 
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints)90 void WindowManagerAgentProxy::UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints)
91 {
92     MessageParcel data;
93     if (!data.WriteInterfaceToken(GetDescriptor())) {
94         WLOGFE("WriteInterfaceToken failed");
95         return;
96     }
97 
98     if (!data.WriteUint64(displayId)) {
99         WLOGFE("Write displayId failed");
100         return;
101     }
102     bool res = MarshallingHelper::MarshallingVectorObj<SystemBarRegionTint>(data, tints,
103         [](Parcel& parcel, const SystemBarRegionTint& tint) {
104             return parcel.WriteUint32(static_cast<uint32_t>(tint.type_)) && parcel.WriteBool(tint.prop_.enable_) &&
105                 parcel.WriteUint32(tint.prop_.backgroundColor_) && parcel.WriteUint32(tint.prop_.contentColor_) &&
106                 parcel.WriteInt32(tint.region_.posX_) && parcel.WriteInt32(tint.region_.posY_) &&
107                 parcel.WriteInt32(tint.region_.width_) && parcel.WriteInt32(tint.region_.height_);
108         }
109     );
110     if (!res) {
111         WLOGFE("Write SystemBarRegionTint failed");
112         return;
113     }
114     MessageParcel reply;
115     MessageOption option(MessageOption::TF_ASYNC);
116     sptr<IRemoteObject> remote = Remote();
117     if (remote == nullptr) {
118         WLOGFE("remote is null");
119         return;
120     }
121     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS),
122         data, reply, option) != ERR_NONE) {
123         WLOGFE("SendRequest failed");
124     }
125 }
126 
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)127 void WindowManagerAgentProxy::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
128     WindowUpdateType type)
129 {
130     MessageParcel data;
131     if (!data.WriteInterfaceToken(GetDescriptor())) {
132         WLOGFE("WriteInterfaceToken failed");
133         return;
134     }
135 
136     if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
137         WLOGFE("Write accessibility window infos failed");
138         return;
139     }
140 
141     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
142         WLOGFE("Write windowUpdateType failed");
143         return;
144     }
145     MessageParcel reply;
146     MessageOption option(MessageOption::TF_ASYNC);
147     sptr<IRemoteObject> remote = Remote();
148     if (remote == nullptr) {
149         WLOGFE("remote is null");
150         return;
151     }
152     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS),
153         data, reply, option) != ERR_NONE) {
154         WLOGFE("SendRequest failed");
155     }
156 }
157 
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & visibilityInfos)158 void WindowManagerAgentProxy::UpdateWindowVisibilityInfo(
159     const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos)
160 {
161     MessageParcel data;
162     if (!data.WriteInterfaceToken(GetDescriptor())) {
163         WLOGFE("WriteInterfaceToken failed");
164         return;
165     }
166     if (!data.WriteUint32(static_cast<uint32_t>(visibilityInfos.size()))) {
167         WLOGFE("write windowVisibilityInfos size failed");
168         return;
169     }
170     for (auto& info : visibilityInfos) {
171         if (!data.WriteParcelable(info)) {
172             WLOGFE("Write windowVisibilityInfo failed");
173             return;
174         }
175     }
176     MessageParcel reply;
177     MessageOption option(MessageOption::TF_ASYNC);
178     sptr<IRemoteObject> remote = Remote();
179     if (remote == nullptr) {
180         WLOGFE("remote is null");
181         return;
182     }
183     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY),
184         data, reply, option) != ERR_NONE) {
185         WLOGFE("SendRequest failed");
186     }
187 }
188 
UpdateWindowDrawingContentInfo(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos)189 void WindowManagerAgentProxy::UpdateWindowDrawingContentInfo(
190     const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos)
191 {
192     MessageParcel data;
193     if (!data.WriteInterfaceToken(GetDescriptor())) {
194         WLOGFE("WriteInterfaceToken failed");
195         return;
196     }
197     if (!data.WriteUint32(static_cast<uint32_t>(windowDrawingContentInfos.size()))) {
198         WLOGFE("write windowDrawingContentInfos size failed");
199         return;
200     }
201     for (auto& info : windowDrawingContentInfos) {
202         if (!data.WriteParcelable(info)) {
203             WLOGFE("Write windowDrawingContentInfos failed");
204             return;
205         }
206     }
207     MessageParcel reply;
208     MessageOption option(MessageOption::TF_ASYNC);
209     sptr<IRemoteObject> remote = Remote();
210     if (remote == nullptr) {
211         WLOGFE("remote is null");
212         return;
213     }
214     if (remote->SendRequest(
215         static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE), data, reply,
216         option) != ERR_NONE) {
217         WLOGFE("SendRequest failed");
218     }
219 }
220 
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)221 void WindowManagerAgentProxy::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
222 {
223     MessageParcel data;
224     if (!data.WriteInterfaceToken(GetDescriptor())) {
225         WLOGFE("WriteInterfaceToken failed");
226         return;
227     }
228 
229     if (!data.WriteUint32(accessTokenId)) {
230         WLOGFE("Write accessTokenId failed");
231         return;
232     }
233 
234     if (!data.WriteBool(isShowing)) {
235         WLOGFE("Write is showing status failed");
236         return;
237     }
238     MessageParcel reply;
239     MessageOption option(MessageOption::TF_ASYNC);
240     sptr<IRemoteObject> remote = Remote();
241     if (remote == nullptr) {
242         WLOGFE("remote is null");
243         return;
244     }
245     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT),
246         data, reply, option) != ERR_NONE) {
247         WLOGFE("SendRequest failed");
248     }
249 }
250 
NotifyWaterMarkFlagChangedResult(bool showWaterMark)251 void WindowManagerAgentProxy::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
252 {
253     MessageParcel data;
254     if (!data.WriteInterfaceToken(GetDescriptor())) {
255         WLOGFE("WriteInterfaceToken failed");
256         return;
257     }
258 
259     if (!data.WriteBool(showWaterMark)) {
260         WLOGFE("Write is showing status failed");
261         return;
262     }
263     MessageParcel reply;
264     MessageOption option(MessageOption::TF_ASYNC);
265     sptr<IRemoteObject> remote = Remote();
266     if (remote == nullptr) {
267         WLOGFE("remote is null");
268         return;
269     }
270     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG),
271         data, reply, option) != ERR_NONE) {
272         WLOGFE("SendRequest failed");
273     }
274 }
275 
UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)276 void WindowManagerAgentProxy::UpdateVisibleWindowNum(
277     const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
278 {
279     MessageParcel data;
280     if (!data.WriteInterfaceToken(GetDescriptor())) {
281         WLOGFE("WriteInterfaceToken failed");
282         return;
283     }
284 
285     bool res = MarshallingHelper::MarshallingVectorObj<VisibleWindowNumInfo>(data, visibleWindowNumInfo,
286         [](Parcel& parcel, const VisibleWindowNumInfo& num) {
287             return parcel.WriteUint32(num.displayId) && parcel.WriteUint32(num.visibleWindowNum);
288         }
289     );
290     if (!res) {
291         WLOGFE("Write VisibleWindowNumInfo failed");
292         return;
293     }
294     MessageParcel reply;
295     MessageOption option(MessageOption::TF_ASYNC);
296     sptr<IRemoteObject> remote = Remote();
297     if (remote == nullptr) {
298         WLOGFE("remote is null");
299         return;
300     }
301     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM),
302         data, reply, option) != ERR_NONE) {
303         WLOGFE("SendRequest failed");
304     }
305 }
306 
NotifyGestureNavigationEnabledResult(bool enable)307 void WindowManagerAgentProxy::NotifyGestureNavigationEnabledResult(bool enable)
308 {
309     MessageParcel data;
310     if (!data.WriteInterfaceToken(GetDescriptor())) {
311         WLOGFE("WriteInterfaceToken failed");
312         return;
313     }
314 
315     if (!data.WriteBool(enable)) {
316         WLOGFE("Write is showing status failed");
317         return;
318     }
319     MessageParcel reply;
320     MessageOption option(MessageOption::TF_ASYNC);
321     sptr<IRemoteObject> remote = Remote();
322     if (remote == nullptr) {
323         WLOGFE("remote is null");
324         return;
325     }
326     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED),
327         data, reply, option) != ERR_NONE) {
328         WLOGFE("SendRequest failed");
329     }
330 }
331 
UpdateCameraWindowStatus(uint32_t accessTokenId,bool isShowing)332 void WindowManagerAgentProxy::UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing)
333 {
334     MessageParcel data;
335     if (!data.WriteInterfaceToken(GetDescriptor())) {
336         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
337         return;
338     }
339     if (!data.WriteUint32(accessTokenId)) {
340         TLOGE(WmsLogTag::WMS_MAIN, "Write accessTokenId failed");
341         return;
342     }
343     if (!data.WriteBool(isShowing)) {
344         TLOGE(WmsLogTag::WMS_MAIN, "Write isShowing status failed");
345         return;
346     }
347     MessageParcel reply;
348     MessageOption option(MessageOption::TF_ASYNC);
349     sptr<IRemoteObject> remote = Remote();
350     if (remote == nullptr) {
351         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
352         return;
353     }
354     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS),
355         data, reply, option) != ERR_NONE) {
356         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
357     }
358 }
359 
NotifyWindowStyleChange(WindowStyleType type)360 void WindowManagerAgentProxy::NotifyWindowStyleChange(WindowStyleType type)
361 {
362     MessageParcel data;
363     MessageParcel reply;
364     MessageOption option(MessageOption::TF_ASYNC);
365     if (!data.WriteInterfaceToken(GetDescriptor())) {
366         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
367         return;
368     }
369     if (!data.WriteUint8(static_cast<uint8_t>(type))) {
370         TLOGE(WmsLogTag::WMS_MAIN, "Write displayId failed");
371         return;
372     }
373     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE),
374         data, reply, option) != ERR_NONE) {
375         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
376     }
377 }
378 
UpdatePiPWindowStateChanged(const std::string & bundleName,bool isForeground)379 void WindowManagerAgentProxy::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground)
380 {
381     MessageParcel data;
382     MessageParcel reply;
383     MessageOption option(MessageOption::TF_ASYNC);
384     if (!data.WriteInterfaceToken(GetDescriptor())) {
385         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
386         return;
387     }
388     if (!data.WriteString(bundleName)) {
389         TLOGE(WmsLogTag::WMS_PIP, "Write bundleName failed");
390         return;
391     }
392     if (!data.WriteBool(isForeground)) {
393         TLOGE(WmsLogTag::WMS_PIP, "Write state failed");
394         return;
395     }
396     sptr<IRemoteObject> remote = Remote();
397     if (remote == nullptr) {
398         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
399         return;
400     }
401     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED),
402         data, reply, option) != ERR_NONE) {
403         TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed");
404     }
405 }
406 } // namespace Rosen
407 } // namespace OHOS
408 
409