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.h"
16
17 #include "session_permission.h"
18 #include "ui_effect_controller_common.h"
19 #include "window_manager_hilog.h"
20
21 namespace OHOS::Rosen {
OnRemoteDied(const wptr<IRemoteObject> & remote)22 void UIEffectControllerClientDeath::OnRemoteDied(const wptr<IRemoteObject>& remote)
23 {
24 if (remote == nullptr) {
25 TLOGE(WmsLogTag::WMS_ANIMATION, "remote is null");
26 return;
27 }
28 if (eraseFunc_) {
29 eraseFunc_();
30 } else {
31 TLOGE(WmsLogTag::WMS_ANIMATION, "failed due to eraseFunc nullptr");
32 }
33 }
34
UIEffectController(int32_t id,const SetParamsFunc & paramCallback,const AnimateToFunc & animateCallback)35 UIEffectController::UIEffectController(int32_t id,
36 const SetParamsFunc& paramCallback, const AnimateToFunc& animateCallback)
37 {
38 id_ = id;
39 setParamsCallback_ = paramCallback;
40 animateToCallback_ = animateCallback;
41 }
42
SetParams(const sptr<UIEffectParams> & params)43 WMError UIEffectController::SetParams(const sptr<UIEffectParams>& params)
44 {
45 if (!SessionPermission::IsSystemCalling()) {
46 TLOGE(WmsLogTag::WMS_ANIMATION, "not system calling, permission denied!");
47 return WMError::WM_ERROR_NOT_SYSTEM_APP;
48 }
49 isAliveInUI_ = true;
50 if (setParamsCallback_) {
51 setParamsCallback_(id_, params);
52 return WMError::WM_OK;
53 } else {
54 TLOGE(WmsLogTag::WMS_ANIMATION, "setParamCallback not exist, id: %{public}d", id_);
55 return WMError::WM_ERROR_NULLPTR;
56 }
57 }
58
AnimateTo(const sptr<UIEffectParams> & params,const sptr<WindowAnimationOption> & config,const sptr<WindowAnimationOption> & interruptOption)59 WMError UIEffectController::AnimateTo(const sptr<UIEffectParams>& params,
60 const sptr<WindowAnimationOption>& config, const sptr<WindowAnimationOption>& interruptOption)
61 {
62 if (!SessionPermission::IsSystemCalling()) {
63 TLOGE(WmsLogTag::WMS_ANIMATION, "not system calling, permission denied!");
64 return WMError::WM_ERROR_NOT_SYSTEM_APP;
65 }
66 if (!isAliveInUI_) {
67 return WMError::WM_ERROR_UI_EFFECT_ERROR;
68 }
69 if (animateToCallback_) {
70 animateToCallback_(id_, params, config, interruptOption);
71 return WMError::WM_OK;
72 } else {
73 TLOGE(WmsLogTag::WMS_ANIMATION, "animateToCallback not exist, id: %{public}d", id_);
74 return WMError::WM_ERROR_NULLPTR;
75 }
76 }
77 }