• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "drag_internal_animation_wrapper.h"
17 
18 #include <dlfcn.h>
19 
20 #include "devicestatus_define.h"
21 #include "fi_log.h"
22 
23 #undef LOG_TAG
24 #define LOG_TAG "DragInternalAnimationWrapper"
25 
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29 namespace {
30 const std::string DRAG_INTERNAL_ANIMATION_SO_PATH = "/system/lib64/libdrag_internal_animation.z.so";
31 }
32 
~DragInternalAnimationWrapper()33 DragInternalAnimationWrapper::~DragInternalAnimationWrapper()
34 {
35     FI_HILOGI("Enter");
36     if (dragInternalAnimationHandle_ != nullptr) {
37         dlclose(dragInternalAnimationHandle_);
38         dragInternalAnimationHandle_ = nullptr;
39     }
40 }
41 
Init()42 bool DragInternalAnimationWrapper::Init()
43 {
44     FI_HILOGI("Enter");
45     if (dragInternalAnimationHandle_ == nullptr) {
46         dragInternalAnimationHandle_ = dlopen(DRAG_INTERNAL_ANIMATION_SO_PATH.c_str(), RTLD_LAZY);
47         char *error = nullptr;
48         if (((error = dlerror()) != nullptr) || (dragInternalAnimationHandle_ == nullptr)) {
49             FI_HILOGE("Couldn't load universal drag handler library with dlopen(). Error: %{public}s", error);
50             return false;
51         }
52     }
53     return true;
54 }
55 
EnableInternalDropAnimation(const std::string & animationInfo)56 int32_t DragInternalAnimationWrapper::EnableInternalDropAnimation(const std::string &animationInfo)
57 {
58     FI_HILOGI("Enter");
59     if ((dragInternalAnimationHandle_ == nullptr) && (!Init())) {
60         FI_HILOGE("Init internal animation handle fail");
61         return RET_ERR;
62     }
63     if (enableInternalDropAnimationHandle_ == nullptr) {
64         enableInternalDropAnimationHandle_ =
65             reinterpret_cast<EnableInternalDropAnimationFunc>(dlsym(dragInternalAnimationHandle_,
66             "EnableInternalDropAnimation"));
67         char *error = nullptr;
68         if ((error = dlerror()) != nullptr) {
69             FI_HILOGE("Symbol enableInternalDropAnimation error: %{public}s", error);
70             return RET_ERR;
71         }
72     }
73     if (enableInternalDropAnimationHandle_ == nullptr) {
74         FI_HILOGE("Symbol enableInternalDropAnimationHandle is null");
75         return RET_ERR;
76     }
77     return enableInternalDropAnimationHandle_(animationInfo.c_str());
78 }
79 
PerformInternalDropAnimation(IContext * env)80 int32_t DragInternalAnimationWrapper::PerformInternalDropAnimation(IContext* env)
81 {
82     CALL_DEBUG_ENTER;
83     if ((dragInternalAnimationHandle_ == nullptr) && (!Init())) {
84         FI_HILOGE("Init internal animation handle fail");
85         return RET_ERR;
86     }
87     if (performInternalDropAnimationHandle_ == nullptr) {
88         performInternalDropAnimationHandle_ =
89             reinterpret_cast<PerformInternalDropAnimationFunc>(dlsym(dragInternalAnimationHandle_,
90             "PerformInternalDropAnimation"));
91         char *error = nullptr;
92         if ((error = dlerror()) != nullptr) {
93             FI_HILOGE("Symbol performInternalDropAnimationHandle error: %{public}s", error);
94             return RET_ERR;
95         }
96     }
97 
98     if (performInternalDropAnimationHandle_ == nullptr) {
99         FI_HILOGE("Symbol performInternalDropAnimationHandle is null");
100         return RET_ERR;
101     }
102     return performInternalDropAnimationHandle_(env);
103 }
104 } // namespace DeviceStatus
105 } // namespace Msdp
106 } // namespace OHOS