1 /*
2 * Copyright (c) 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 "rs_window_animation_proxy.h"
17
18 #include "rs_iwindow_animation_finished_callback.h"
19 #include "rs_window_animation_log.h"
20 #include "rs_window_animation_target.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 static constexpr int MAX_FLOATING_WINDOW_NUMBER = 100;
26 }
RSWindowAnimationProxy(const sptr<IRemoteObject> & impl)27 RSWindowAnimationProxy::RSWindowAnimationProxy(const sptr<IRemoteObject>& impl)
28 : IRemoteProxy<RSIWindowAnimationController>(impl)
29 {
30 }
31
WriteInterfaceToken(MessageParcel & data)32 bool RSWindowAnimationProxy::WriteInterfaceToken(MessageParcel& data)
33 {
34 if (!data.WriteInterfaceToken(RSWindowAnimationProxy::GetDescriptor())) {
35 WALOGE("Failed to write interface token!");
36 return false;
37 }
38
39 return true;
40 }
41
WriteTargetAndCallback(MessageParcel & data,const sptr<RSWindowAnimationTarget> & windowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)42 bool RSWindowAnimationProxy::WriteTargetAndCallback(MessageParcel& data,
43 const sptr<RSWindowAnimationTarget>& windowTarget,
44 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
45 {
46 if (!data.WriteParcelable(windowTarget.GetRefPtr())) {
47 WALOGE("Failed to write window animation target!");
48 return false;
49 }
50
51 if (!data.WriteRemoteObject(finishedCallback->AsObject())) {
52 WALOGE("Failed to write finished callback!");
53 return false;
54 }
55
56 return true;
57 }
58
OnStartApp(StartingAppType type,const sptr<RSWindowAnimationTarget> & startingWindowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)59 void RSWindowAnimationProxy::OnStartApp(StartingAppType type, const sptr<RSWindowAnimationTarget>& startingWindowTarget,
60 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option(MessageOption::TF_ASYNC);
65
66 WALOGD("Window animation proxy on start app!");
67 if (!WriteInterfaceToken(data)) {
68 return;
69 }
70
71 if (!data.WriteInt32(type)) {
72 WALOGE("Failed to write starting app type!");
73 return;
74 }
75
76 if (!WriteTargetAndCallback(data, startingWindowTarget, finishedCallback)) {
77 WALOGE("Failed to write window animation target or callback!");
78 return;
79 }
80
81 auto remote = Remote();
82 if (remote == nullptr) {
83 WALOGE("remote is null!");
84 return;
85 }
86
87 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_START_APP, data, reply, option);
88 if (ret != NO_ERROR) {
89 WALOGE("Failed to send start app request, error code:%d", ret);
90 }
91 }
92
OnAppTransition(const sptr<RSWindowAnimationTarget> & fromWindowTarget,const sptr<RSWindowAnimationTarget> & toWindowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)93 void RSWindowAnimationProxy::OnAppTransition(const sptr<RSWindowAnimationTarget>& fromWindowTarget,
94 const sptr<RSWindowAnimationTarget>& toWindowTarget,
95 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option(MessageOption::TF_ASYNC);
100
101 WALOGD("Window animation proxy on app transition!");
102 if (!WriteInterfaceToken(data)) {
103 return;
104 }
105
106 if (!data.WriteParcelable(fromWindowTarget.GetRefPtr())) {
107 WALOGE("OnAppTransition failed to write from animation target!");
108 return;
109 }
110
111 if (!data.WriteParcelable(toWindowTarget.GetRefPtr())) {
112 WALOGE("OnAppTransition failed to write to animation target!");
113 return;
114 }
115
116 if (!data.WriteRemoteObject(finishedCallback->AsObject())) {
117 WALOGE("OnAppTransition failed to write finished callback!");
118 return;
119 }
120
121 auto remote = Remote();
122 if (remote == nullptr) {
123 WALOGE("OnAppTransition remote is null!");
124 return;
125 }
126
127 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_APP_TRANSITION, data, reply, option);
128 if (ret != NO_ERROR) {
129 WALOGE("Failed to send app transition request, error code:%d", ret);
130 }
131 }
132
OnAppBackTransition(const sptr<RSWindowAnimationTarget> & fromWindowTarget,const sptr<RSWindowAnimationTarget> & toWindowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)133 void RSWindowAnimationProxy::OnAppBackTransition(const sptr<RSWindowAnimationTarget>& fromWindowTarget,
134 const sptr<RSWindowAnimationTarget>& toWindowTarget,
135 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
136 {
137 MessageParcel data;
138 MessageParcel reply;
139 MessageOption option(MessageOption::TF_ASYNC);
140
141 WALOGD("Window animation proxy on app back transition!");
142 if (!WriteInterfaceToken(data)) {
143 return;
144 }
145
146 if (!data.WriteParcelable(fromWindowTarget.GetRefPtr())) {
147 WALOGE("OnAppBackTransition failed to write from animation target!");
148 return;
149 }
150
151 if (!data.WriteParcelable(toWindowTarget.GetRefPtr())) {
152 WALOGE("OnAppBackTransition failed to write to animation target!");
153 return;
154 }
155
156 if (!data.WriteRemoteObject(finishedCallback->AsObject())) {
157 WALOGE("OnAppBackTransition failed to write finished callback!");
158 return;
159 }
160
161 auto remote = Remote();
162 if (remote == nullptr) {
163 WALOGE("OnAppBackTransition remote is null!");
164 return;
165 }
166
167 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_APP_BACK_TRANSITION, data, reply, option);
168 if (ret != NO_ERROR) {
169 WALOGE("Failed to send app back transition request, error code:%d", ret);
170 }
171 }
172
173
OnMinimizeWindow(const sptr<RSWindowAnimationTarget> & minimizingWindowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)174 void RSWindowAnimationProxy::OnMinimizeWindow(const sptr<RSWindowAnimationTarget>& minimizingWindowTarget,
175 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
176 {
177 MessageParcel data;
178 MessageParcel reply;
179 MessageOption option(MessageOption::TF_ASYNC);
180
181 WALOGD("Window animation proxy on minimize window!");
182 if (!WriteInterfaceToken(data)) {
183 return;
184 }
185
186 if (!WriteTargetAndCallback(data, minimizingWindowTarget, finishedCallback)) {
187 WALOGE("OnMinimizeWindow failed to write window animation target or callback!");
188 return;
189 }
190
191 auto remote = Remote();
192 if (remote == nullptr) {
193 WALOGE("OnMinimizeWindow remote is null!");
194 return;
195 }
196
197 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_MINIMIZE_WINDOW, data, reply, option);
198 if (ret != NO_ERROR) {
199 WALOGE("Failed to send minimize window request, error code:%d", ret);
200 }
201 }
202
OnMinimizeAllWindow(std::vector<sptr<RSWindowAnimationTarget>> minimizingWindowsTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)203 void RSWindowAnimationProxy::OnMinimizeAllWindow(std::vector<sptr<RSWindowAnimationTarget>> minimizingWindowsTarget,
204 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
205 {
206 if (minimizingWindowsTarget.empty()) {
207 if (finishedCallback != nullptr) {
208 finishedCallback->OnAnimationFinished();
209 }
210 WALOGE("The minimizing Windows vector is empty!");
211 return;
212 }
213
214 MessageParcel data;
215 MessageParcel reply;
216 MessageOption option(MessageOption::TF_ASYNC);
217
218 WALOGD("Window animation proxy on minimize all windows!");
219 if (!WriteInterfaceToken(data)) {
220 return;
221 }
222
223 if (!data.WriteUint32(minimizingWindowsTarget.size())) {
224 WALOGE("OnMinimizeAllWindow failed to write minimizing animation target size!");
225 return;
226 }
227
228 for (auto& target : minimizingWindowsTarget) {
229 if (!data.WriteParcelable(target.GetRefPtr())) {
230 WALOGE("OnMinimizeAllWindow failed to write minimizing animation target!");
231 return;
232 }
233 }
234
235 if (!data.WriteRemoteObject(finishedCallback->AsObject())) {
236 WALOGE("OnMinimizeAllWindow failed to write finished callback!");
237 return;
238 }
239
240 auto remote = Remote();
241 if (remote == nullptr) {
242 WALOGE("OnMinimizeAllWindow remote is null!");
243 return;
244 }
245
246 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_MINIMIZE_ALLWINDOW, data, reply, option);
247 if (ret != NO_ERROR) {
248 WALOGE("Failed to send minimize all windows request, error code:%d", ret);
249 }
250 }
251
OnCloseWindow(const sptr<RSWindowAnimationTarget> & closingWindowTarget,const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)252 void RSWindowAnimationProxy::OnCloseWindow(const sptr<RSWindowAnimationTarget>& closingWindowTarget,
253 const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
254 {
255 MessageParcel data;
256 MessageParcel reply;
257 MessageOption option(MessageOption::TF_ASYNC);
258
259 WALOGD("Window animation proxy on close window!");
260 if (!WriteInterfaceToken(data)) {
261 return;
262 }
263
264 if (!WriteTargetAndCallback(data, closingWindowTarget, finishedCallback)) {
265 WALOGE("OnCloseWindow failed to write window animation target or callback!");
266 return;
267 }
268
269 auto remote = Remote();
270 if (remote == nullptr) {
271 WALOGE("OnCloseWindow remote is null!");
272 return;
273 }
274
275 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_CLOSE_WINDOW, data, reply, option);
276 if (ret != NO_ERROR) {
277 WALOGE("OnCloseWindow failed to send close window request, error code:%d", ret);
278 }
279 }
280
OnScreenUnlock(const sptr<RSIWindowAnimationFinishedCallback> & finishedCallback)281 void RSWindowAnimationProxy::OnScreenUnlock(const sptr<RSIWindowAnimationFinishedCallback>& finishedCallback)
282 {
283 MessageParcel data;
284 MessageParcel reply;
285 MessageOption option(MessageOption::TF_ASYNC);
286
287 WALOGD("Window animation proxy on screen unlock!");
288 if (!WriteInterfaceToken(data)) {
289 return;
290 }
291
292 if (!data.WriteRemoteObject(finishedCallback->AsObject())) {
293 WALOGE("OnScreenUnlock failed to write finished callback!");
294 return;
295 }
296
297 auto remote = Remote();
298 if (remote == nullptr) {
299 WALOGE("OnScreenUnlock remote is null!");
300 return;
301 }
302
303 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_SCREEN_UNLOCK, data, reply, option);
304 if (ret != NO_ERROR) {
305 WALOGE("Failed to send screen unlock request, error code:%d", ret);
306 }
307 }
308
OnWindowAnimationTargetsUpdate(const sptr<RSWindowAnimationTarget> & fullScreenWindowTarget,const std::vector<sptr<RSWindowAnimationTarget>> & floatingWindowTargets)309 void RSWindowAnimationProxy::OnWindowAnimationTargetsUpdate(
310 const sptr<RSWindowAnimationTarget>& fullScreenWindowTarget,
311 const std::vector<sptr<RSWindowAnimationTarget>>& floatingWindowTargets)
312 {
313 if (floatingWindowTargets.size() > MAX_FLOATING_WINDOW_NUMBER) {
314 WALOGE("Floating windows are too much!");
315 return;
316 }
317
318 MessageParcel data;
319 MessageParcel reply;
320 MessageOption option(MessageOption::TF_ASYNC);
321
322 WALOGD("Window animation proxy on window animation targets update!");
323 if (!WriteInterfaceToken(data)) {
324 return;
325 }
326
327 if (fullScreenWindowTarget.GetRefPtr() == nullptr) {
328 if (!data.WriteBool(false)) {
329 WALOGE("Failed to write null full Screen Window Target!");
330 return;
331 }
332 } else {
333 if (!data.WriteBool(true) || !data.WriteParcelable(fullScreenWindowTarget.GetRefPtr())) {
334 WALOGE("Failed to write full screen animation target!");
335 return;
336 }
337 }
338
339 if (!data.WriteUint32(floatingWindowTargets.size())) {
340 WALOGE("Failed to write floating animation target size!");
341 return;
342 }
343
344 for (auto& target : floatingWindowTargets) {
345 if (!data.WriteParcelable(target.GetRefPtr())) {
346 WALOGE("Failed to write floating animation target!");
347 return;
348 }
349 }
350
351 auto remote = Remote();
352 if (remote == nullptr) {
353 WALOGE("remote is null!");
354 return;
355 }
356
357 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_WINDOW_ANIMATION_TARGETS_UPDATE,
358 data, reply, option);
359 if (ret != NO_ERROR) {
360 WALOGE("Failed to send window animation targets update request, error code:%d", ret);
361 }
362 }
363
OnWallpaperUpdate(const sptr<RSWindowAnimationTarget> & wallpaperTarget)364 void RSWindowAnimationProxy::OnWallpaperUpdate(const sptr<RSWindowAnimationTarget>& wallpaperTarget)
365 {
366 MessageParcel data;
367 MessageParcel reply;
368 MessageOption option(MessageOption::TF_ASYNC);
369
370 WALOGD("Window animation proxy on wallpaper update!");
371 if (!WriteInterfaceToken(data)) {
372 return;
373 }
374
375 if (!data.WriteParcelable(wallpaperTarget.GetRefPtr())) {
376 WALOGE("Failed to write wallpaper update target!");
377 return;
378 }
379
380 auto remote = Remote();
381 if (remote == nullptr) {
382 WALOGE("remote is null!");
383 return;
384 }
385
386 auto ret = remote->SendRequest(RSIWindowAnimationController::ON_WALLPAPER_UPDATE, data, reply, option);
387 if (ret != NO_ERROR) {
388 WALOGE("Failed to send wallpaper update request, error code:%d", ret);
389 }
390 }
391 } // namespace Rosen
392 } // namespace OHOS
393