1 /*
2 * Copyright (c) 2025 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 #include "ui_effect_controller_proxy.h"
16
17 #include "ui_effect_controller_common.h"
18
19 namespace OHOS::Rosen {
SetParams(const sptr<UIEffectParams> & params)20 WMError UIEffectControllerProxy::SetParams(const sptr<UIEffectParams>& params)
21 {
22 MessageParcel data;
23 MessageParcel reply;
24 MessageOption option(MessageOption::TF_SYNC);
25 if (!data.WriteInterfaceToken(GetDescriptor())) {
26 TLOGE(WmsLogTag::WMS_ANIMATION, "Write interfaceToken failed");
27 return WMError::WM_ERROR_IPC_FAILED;
28 }
29 if (!data.WriteStrongParcelable(params)) {
30 TLOGE(WmsLogTag::WMS_ANIMATION, "Write ui effect params failed");
31 return WMError::WM_ERROR_IPC_FAILED;
32 }
33 sptr<IRemoteObject> remote = Remote();
34 if (remote == nullptr) {
35 TLOGE(WmsLogTag::WMS_ANIMATION, "remote is null");
36 return WMError::WM_ERROR_IPC_FAILED;
37 }
38 if (remote->SendRequest(static_cast<uint32_t>(UIEffectControllerMessage::TRANS_ID_UIEFFECT_SET_PARAM),
39 data, reply, option) != ERR_NONE) {
40 TLOGE(WmsLogTag::WMS_ANIMATION, "SendRequest failed");
41 return WMError::WM_ERROR_IPC_FAILED;
42 }
43 uint32_t ret = 0;
44 if (!reply.ReadUint32(ret)) {
45 TLOGE(WmsLogTag::WMS_ANIMATION, "Read ret failed");
46 return WMError::WM_ERROR_IPC_FAILED;
47 }
48 return static_cast<WMError>(ret);
49 }
AnimateTo(const sptr<UIEffectParams> & params,const sptr<WindowAnimationOption> & config,const sptr<WindowAnimationOption> & interruptedOption)50 WMError UIEffectControllerProxy::AnimateTo(const sptr<UIEffectParams>& params,
51 const sptr<WindowAnimationOption>& config, const sptr<WindowAnimationOption>& interruptedOption)
52 {
53 MessageParcel data;
54 MessageParcel reply;
55 MessageOption option(MessageOption::TF_SYNC);
56 if (!data.WriteInterfaceToken(GetDescriptor())) {
57 TLOGE(WmsLogTag::WMS_ANIMATION, "Write interfaceToken failed");
58 return WMError::WM_ERROR_IPC_FAILED;
59 }
60 if (!data.WriteStrongParcelable(params)) {
61 TLOGE(WmsLogTag::WMS_ANIMATION, "Write ui effect params failed");
62 return WMError::WM_ERROR_IPC_FAILED;
63 }
64 if (!data.WriteStrongParcelable(config)) {
65 TLOGE(WmsLogTag::WMS_ANIMATION, "Write window animation config failed");
66 return WMError::WM_ERROR_IPC_FAILED;
67 }
68 if (!data.WriteBool(interruptedOption != nullptr)) {
69 TLOGE(WmsLogTag::WMS_ANIMATION, "Write window has interrupt option failed");
70 return WMError::WM_ERROR_IPC_FAILED;
71 }
72 if (interruptedOption != nullptr) {
73 if (!data.WriteStrongParcelable(interruptedOption)) {
74 TLOGE(WmsLogTag::WMS_ANIMATION, "Write window interrupt config failed");
75 return WMError::WM_ERROR_IPC_FAILED;
76 }
77 }
78 sptr<IRemoteObject> remote = Remote();
79 if (remote == nullptr) {
80 TLOGE(WmsLogTag::WMS_ANIMATION, "remote is null");
81 return WMError::WM_ERROR_IPC_FAILED;
82 }
83 if (remote->SendRequest(static_cast<uint32_t>(UIEffectControllerMessage::TRANS_ID_UIEFFECT_ANIMATE_TO),
84 data, reply, option) != ERR_NONE) {
85 TLOGE(WmsLogTag::WMS_ANIMATION, "SendRequest failed");
86 return WMError::WM_ERROR_IPC_FAILED;
87 }
88 uint32_t ret = 0;
89 if (!reply.ReadUint32(ret)) {
90 TLOGE(WmsLogTag::WMS_ANIMATION, "Read ret failed");
91 return WMError::WM_ERROR_IPC_FAILED;
92 }
93 return static_cast<WMError>(ret);
94 }
95 }