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 MessageParcel reply;
32 MessageOption option(MessageOption::TF_ASYNC);
33 if (focusChangeInfo == nullptr) {
34 WLOGFE("Invalid focus change info");
35 return;
36 }
37
38 if (!data.WriteInterfaceToken(GetDescriptor())) {
39 WLOGFE("WriteInterfaceToken failed");
40 return;
41 }
42
43 if (!data.WriteParcelable(focusChangeInfo)) {
44 WLOGFE("Write displayId failed");
45 return;
46 }
47
48 if (!data.WriteRemoteObject(focusChangeInfo->abilityToken_)) {
49 WLOGFI("Write abilityToken failed");
50 }
51
52 if (!data.WriteBool(focused)) {
53 WLOGFE("Write Focus failed");
54 return;
55 }
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
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints)63 void WindowManagerAgentProxy::UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints)
64 {
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option(MessageOption::TF_ASYNC);
68 if (!data.WriteInterfaceToken(GetDescriptor())) {
69 WLOGFE("WriteInterfaceToken failed");
70 return;
71 }
72
73 if (!data.WriteUint64(displayId)) {
74 WLOGFE("Write displayId failed");
75 return;
76 }
77 bool res = MarshallingHelper::MarshallingVectorObj<SystemBarRegionTint>(data, tints,
78 [](Parcel& parcel, const SystemBarRegionTint& tint) {
79 return parcel.WriteUint32(static_cast<uint32_t>(tint.type_)) && parcel.WriteBool(tint.prop_.enable_) &&
80 parcel.WriteUint32(tint.prop_.backgroundColor_) && parcel.WriteUint32(tint.prop_.contentColor_) &&
81 parcel.WriteInt32(tint.region_.posX_) && parcel.WriteInt32(tint.region_.posY_) &&
82 parcel.WriteInt32(tint.region_.width_) && parcel.WriteInt32(tint.region_.height_);
83 }
84 );
85 if (!res) {
86 WLOGFE("Write SystemBarRegionTint failed");
87 return;
88 }
89 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS),
90 data, reply, option) != ERR_NONE) {
91 WLOGFE("SendRequest failed");
92 }
93 }
94
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)95 void WindowManagerAgentProxy::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
96 WindowUpdateType type)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option(MessageOption::TF_ASYNC);
101 if (!data.WriteInterfaceToken(GetDescriptor())) {
102 WLOGFE("WriteInterfaceToken failed");
103 return;
104 }
105
106 if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
107 WLOGFE("Write accessibility window infos failed");
108 return;
109 }
110
111 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
112 WLOGFE("Write windowUpdateType failed");
113 return;
114 }
115 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS),
116 data, reply, option) != ERR_NONE) {
117 WLOGFE("SendRequest failed");
118 }
119 }
120
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & visibilityInfos)121 void WindowManagerAgentProxy::UpdateWindowVisibilityInfo(
122 const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos)
123 {
124 MessageParcel data;
125 MessageParcel reply;
126 MessageOption option(MessageOption::TF_ASYNC);
127 if (!data.WriteInterfaceToken(GetDescriptor())) {
128 WLOGFE("WriteInterfaceToken failed");
129 return;
130 }
131 if (!data.WriteUint32(static_cast<uint32_t>(visibilityInfos.size()))) {
132 WLOGFE("write windowVisibilityInfos size failed");
133 return;
134 }
135 for (auto& info : visibilityInfos) {
136 if (!data.WriteParcelable(info)) {
137 WLOGFE("Write windowVisibilityInfo failed");
138 return;
139 }
140 }
141
142 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY),
143 data, reply, option) != ERR_NONE) {
144 WLOGFE("SendRequest failed");
145 }
146 }
147
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)148 void WindowManagerAgentProxy::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
149 {
150 MessageParcel data;
151 MessageParcel reply;
152 MessageOption option(MessageOption::TF_ASYNC);
153 if (!data.WriteInterfaceToken(GetDescriptor())) {
154 WLOGFE("WriteInterfaceToken failed");
155 return;
156 }
157
158 if (!data.WriteUint32(accessTokenId)) {
159 WLOGFE("Write accessTokenId failed");
160 return;
161 }
162
163 if (!data.WriteBool(isShowing)) {
164 WLOGFE("Write is showing status failed");
165 return;
166 }
167
168 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT),
169 data, reply, option) != ERR_NONE) {
170 WLOGFE("SendRequest failed");
171 }
172 }
173 } // namespace Rosen
174 } // namespace OHOS
175
176