1 /*
2 * Copyright (c) 2022-2024 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 #ifdef SUPPORT_GRAPHICS
17 #include "window_manager_service_handler_proxy.h"
18
19 #include "ability_manager_errors.h"
20 #include "hilog_tag_wrapper.h"
21 #include "parcel.h"
22
23 namespace OHOS {
24 namespace AAFwk {
WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> & impl)25 WindowManagerServiceHandlerProxy::WindowManagerServiceHandlerProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<IWindowManagerServiceHandler>(impl) {}
27
NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,sptr<AbilityTransitionInfo> toInfo,bool & animaEnabled)28 void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptr<AbilityTransitionInfo> fromInfo,
29 sptr<AbilityTransitionInfo> toInfo, bool& animaEnabled)
30 {
31 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
32 MessageParcel data;
33 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
34 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
35 return;
36 }
37 if (!data.WriteParcelable(fromInfo.GetRefPtr())) {
38 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write fromInfo failed");
39 return;
40 }
41 if (!data.WriteParcelable(toInfo.GetRefPtr())) {
42 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write toInfo failed");
43 return;
44 }
45 if (!data.WriteBool(animaEnabled)) {
46 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write animaEnabled failed");
47 return;
48 }
49 MessageParcel reply;
50 MessageOption option(MessageOption::TF_ASYNC);
51 int error = SendTransactCmd(WMSCmd::ON_NOTIFY_WINDOW_TRANSITION, data, reply, option);
52 if (error != ERR_OK) {
53 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
54 }
55 animaEnabled = reply.ReadBool();
56 }
57
GetFocusWindow(sptr<IRemoteObject> & abilityToken)58 int32_t WindowManagerServiceHandlerProxy::GetFocusWindow(sptr<IRemoteObject>& abilityToken)
59 {
60 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
61 MessageParcel data;
62 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
63 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
64 return ERR_AAFWK_PARCEL_FAIL;
65 }
66
67 MessageParcel reply;
68 MessageOption option;
69 int error = SendTransactCmd(WMSCmd::ON_GET_FOCUS_ABILITY, data, reply, option);
70 if (error != ERR_OK) {
71 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
72 return ERR_AAFWK_PARCEL_FAIL;
73 }
74 auto ret = reply.ReadInt32();
75 if (ret == 0 && reply.ReadBool()) {
76 abilityToken = reply.ReadRemoteObject();
77 }
78 TAG_LOGD(AAFwkTag::ABILITYMGR, "ending");
79 return ret;
80 }
81
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap,uint32_t bgColor)82 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
83 std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bgColor)
84 {
85 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
86 MessageParcel data;
87 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
88 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write token");
89 return;
90 }
91 if (!data.WriteParcelable(info.GetRefPtr())) {
92 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write info failed");
93 return;
94 }
95 if (!data.WriteParcelable(pixelMap.get())) {
96 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write pixelMap failed");
97 return;
98 }
99 if (!data.WriteUint32(bgColor)) {
100 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write bgColor");
101 return;
102 }
103 MessageParcel reply;
104 MessageOption option(MessageOption::TF_ASYNC);
105 int error = SendTransactCmd(WMSCmd::ON_COLD_STARTING_WINDOW, data, reply, option);
106 if (error != ERR_OK) {
107 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
108 }
109 }
110
StartingWindow(sptr<AbilityTransitionInfo> info,std::shared_ptr<Media::PixelMap> pixelMap)111 void WindowManagerServiceHandlerProxy::StartingWindow(sptr<AbilityTransitionInfo> info,
112 std::shared_ptr<Media::PixelMap> pixelMap)
113 {
114 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
115 MessageParcel data;
116 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
117 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
118 return;
119 }
120 if (!data.WriteParcelable(info.GetRefPtr())) {
121 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write info failed");
122 return;
123 }
124 if (!data.WriteParcelable(pixelMap.get())) {
125 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write pixelMap");
126 return;
127 }
128 MessageParcel reply;
129 MessageOption option(MessageOption::TF_ASYNC);
130 int error = SendTransactCmd(WMSCmd::ON_HOT_STARTING_WINDOW, data, reply, option);
131 if (error != ERR_OK) {
132 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
133 }
134 }
135
CancelStartingWindow(sptr<IRemoteObject> abilityToken)136 void WindowManagerServiceHandlerProxy::CancelStartingWindow(sptr<IRemoteObject> abilityToken)
137 {
138 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
139 MessageParcel data;
140 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
141 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
142 return;
143 }
144 if (!abilityToken) {
145 if (!data.WriteBool(false)) {
146 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write false");
147 return;
148 }
149 } else {
150 if (!data.WriteBool(true)) {
151 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write true failed");
152 return;
153 }
154 if (!data.WriteRemoteObject(abilityToken)) {
155 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write abilityToken failed");
156 return;
157 }
158 }
159 MessageParcel reply;
160 MessageOption option(MessageOption::TF_ASYNC);
161 int error = SendTransactCmd(WMSCmd::ON_CANCEL_STARTING_WINDOW, data, reply, option);
162 if (error != ERR_OK) {
163 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
164 }
165 }
166
NotifyAnimationAbilityDied(sptr<AbilityTransitionInfo> info)167 void WindowManagerServiceHandlerProxy::NotifyAnimationAbilityDied(sptr<AbilityTransitionInfo> info)
168 {
169 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
170 MessageParcel data;
171 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
172 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write token failed");
173 return;
174 }
175 if (!data.WriteParcelable(info.GetRefPtr())) {
176 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write info");
177 return;
178 }
179 MessageParcel reply;
180 MessageOption option(MessageOption::TF_ASYNC);
181 int error = SendTransactCmd(WMSCmd::ON_NOTIFY_ANIMATION_ABILITY_DIED, data, reply, option);
182 if (error != ERR_OK) {
183 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest error: %{public}d", error);
184 }
185 }
186
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)187 int32_t WindowManagerServiceHandlerProxy::MoveMissionsToForeground(const std::vector<int32_t>& missionIds,
188 int32_t topMissionId)
189 {
190 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
191 MessageParcel data;
192 MessageParcel reply;
193 MessageOption option;
194
195 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
196 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
197 return ERR_AAFWK_PARCEL_FAIL;
198 }
199
200 if (!data.WriteInt32Vector(missionIds)) {
201 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write missionIds failed");
202 return ERR_AAFWK_PARCEL_FAIL;
203 }
204
205 if (!data.WriteInt32(topMissionId)) {
206 TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write TopMissionId");
207 return ERR_AAFWK_PARCEL_FAIL;
208 }
209
210 int error = SendTransactCmd(WMSCmd::ON_MOVE_MISSINONS_TO_FOREGROUND, data, reply, option);
211 if (error != ERR_NONE) {
212 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendoRequest error: %{public}d", error);
213 return ERR_AAFWK_PARCEL_FAIL;
214 }
215 return reply.ReadInt32();
216 }
217
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)218 int32_t WindowManagerServiceHandlerProxy::MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
219 std::vector<int32_t>& result)
220 {
221 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option;
225
226 if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) {
227 TAG_LOGE(AAFwkTag::ABILITYMGR, "WriteInterfaceToken failed");
228 return ERR_AAFWK_PARCEL_FAIL;
229 }
230
231 if (!data.WriteInt32Vector(missionIds)) {
232 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write missionIds failed");
233 return ERR_AAFWK_PARCEL_FAIL;
234 }
235
236 int error = SendTransactCmd(WMSCmd::ON_MOVE_MISSIONS_TO_BACKGROUND, data, reply, option);
237 if (error != ERR_NONE) {
238 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendoRequest error: %{public}d", error);
239 return ERR_AAFWK_PARCEL_FAIL;
240 }
241 if (!reply.ReadInt32Vector(&result)) {
242 TAG_LOGE(AAFwkTag::ABILITYMGR, "Read hide result failed");
243 return ERR_AAFWK_PARCEL_FAIL;
244 };
245 return reply.ReadInt32();
246 }
247
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)248 int32_t WindowManagerServiceHandlerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
249 MessageParcel &reply, MessageOption &option)
250 {
251 sptr<IRemoteObject> remote = Remote();
252 if (remote == nullptr) {
253 TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
254 return ERR_NULL_OBJECT;
255 }
256
257 int32_t ret = remote->SendRequest(code, data, reply, option);
258 if (ret != ERR_OK) {
259 TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest failed. code: %{public}d, ret: %{public}d", code, ret);
260 return ret;
261 }
262 return ERR_OK;
263 }
264 } // namespace AAFwk
265 } // namespace OHOS
266 #endif
267