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 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS),
53 data, reply, option) != ERR_NONE) {
54 WLOGFE("SendRequest failed");
55 }
56 }
57
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints)58 void WindowManagerAgentProxy::UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints)
59 {
60 MessageParcel data;
61 if (!data.WriteInterfaceToken(GetDescriptor())) {
62 WLOGFE("WriteInterfaceToken failed");
63 return;
64 }
65
66 if (!data.WriteUint64(displayId)) {
67 WLOGFE("Write displayId failed");
68 return;
69 }
70 bool res = MarshallingHelper::MarshallingVectorObj<SystemBarRegionTint>(data, tints,
71 [](Parcel& parcel, const SystemBarRegionTint& tint) {
72 return parcel.WriteUint32(static_cast<uint32_t>(tint.type_)) && parcel.WriteBool(tint.prop_.enable_) &&
73 parcel.WriteUint32(tint.prop_.backgroundColor_) && parcel.WriteUint32(tint.prop_.contentColor_) &&
74 parcel.WriteInt32(tint.region_.posX_) && parcel.WriteInt32(tint.region_.posY_) &&
75 parcel.WriteInt32(tint.region_.width_) && parcel.WriteInt32(tint.region_.height_);
76 }
77 );
78 if (!res) {
79 WLOGFE("Write SystemBarRegionTint failed");
80 return;
81 }
82 MessageParcel reply;
83 MessageOption option(MessageOption::TF_ASYNC);
84 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS),
85 data, reply, option) != ERR_NONE) {
86 WLOGFE("SendRequest failed");
87 }
88 }
89
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)90 void WindowManagerAgentProxy::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
91 WindowUpdateType type)
92 {
93 MessageParcel data;
94 if (!data.WriteInterfaceToken(GetDescriptor())) {
95 WLOGFE("WriteInterfaceToken failed");
96 return;
97 }
98
99 if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
100 WLOGFE("Write accessibility window infos failed");
101 return;
102 }
103
104 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
105 WLOGFE("Write windowUpdateType failed");
106 return;
107 }
108 MessageParcel reply;
109 MessageOption option(MessageOption::TF_ASYNC);
110 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS),
111 data, reply, option) != ERR_NONE) {
112 WLOGFE("SendRequest failed");
113 }
114 }
115
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & visibilityInfos)116 void WindowManagerAgentProxy::UpdateWindowVisibilityInfo(
117 const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos)
118 {
119 MessageParcel data;
120 if (!data.WriteInterfaceToken(GetDescriptor())) {
121 WLOGFE("WriteInterfaceToken failed");
122 return;
123 }
124 if (!data.WriteUint32(static_cast<uint32_t>(visibilityInfos.size()))) {
125 WLOGFE("write windowVisibilityInfos size failed");
126 return;
127 }
128 for (auto& info : visibilityInfos) {
129 if (!data.WriteParcelable(info)) {
130 WLOGFE("Write windowVisibilityInfo failed");
131 return;
132 }
133 }
134 MessageParcel reply;
135 MessageOption option(MessageOption::TF_ASYNC);
136 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY),
137 data, reply, option) != ERR_NONE) {
138 WLOGFE("SendRequest failed");
139 }
140 }
141
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)142 void WindowManagerAgentProxy::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
143 {
144 MessageParcel data;
145 if (!data.WriteInterfaceToken(GetDescriptor())) {
146 WLOGFE("WriteInterfaceToken failed");
147 return;
148 }
149
150 if (!data.WriteUint32(accessTokenId)) {
151 WLOGFE("Write accessTokenId failed");
152 return;
153 }
154
155 if (!data.WriteBool(isShowing)) {
156 WLOGFE("Write is showing status failed");
157 return;
158 }
159 MessageParcel reply;
160 MessageOption option(MessageOption::TF_ASYNC);
161 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT),
162 data, reply, option) != ERR_NONE) {
163 WLOGFE("SendRequest failed");
164 }
165 }
166
NotifyWaterMarkFlagChangedResult(bool showWaterMark)167 void WindowManagerAgentProxy::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
168 {
169 MessageParcel data;
170 if (!data.WriteInterfaceToken(GetDescriptor())) {
171 WLOGFE("WriteInterfaceToken failed");
172 return;
173 }
174
175 if (!data.WriteBool(showWaterMark)) {
176 WLOGFE("Write is showing status failed");
177 return;
178 }
179 MessageParcel reply;
180 MessageOption option(MessageOption::TF_ASYNC);
181 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG),
182 data, reply, option) != ERR_NONE) {
183 WLOGFE("SendRequest failed");
184 }
185 }
NotifyGestureNavigationEnabledResult(bool enable)186 void WindowManagerAgentProxy::NotifyGestureNavigationEnabledResult(bool enable)
187 {
188 MessageParcel data;
189 if (!data.WriteInterfaceToken(GetDescriptor())) {
190 WLOGFE("WriteInterfaceToken failed");
191 return;
192 }
193
194 if (!data.WriteBool(enable)) {
195 WLOGFE("Write is showing status failed");
196 return;
197 }
198 MessageParcel reply;
199 MessageOption option(MessageOption::TF_ASYNC);
200 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED),
201 data, reply, option) != ERR_NONE) {
202 WLOGFE("SendRequest failed");
203 }
204 }
205
206 } // namespace Rosen
207 } // namespace OHOS
208
209