1 /* 2 * Copyright (c) 2023 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 "plugin_manager.h" 17 18 #include <string_view> 19 20 #include "devicestatus_define.h" 21 #include "utility.h" 22 23 #undef LOG_TAG 24 #define LOG_TAG "PluginManager" 25 26 namespace OHOS { 27 namespace Msdp { 28 namespace DeviceStatus { 29 30 #if (defined(__aarch64__) || defined(__x86_64__)) 31 constexpr std::string_view LIB_COOPERATE_PATH { "/system/lib64/libintention_cooperate.z.so" }; 32 constexpr std::string_view LIB_MOTION_DRAG_PATH { "/system/lib64/libmotion_drag.z.so" }; 33 #else 34 constexpr std::string_view LIB_COOPERATE_PATH { "/system/lib/libintention_cooperate.z.so" }; 35 constexpr std::string_view LIB_MOTION_DRAG_PATH { "/system/lib/libmotion_drag.z.so" }; 36 #endif // defined(__x86_64__) 37 LoadCooperate()38ICooperate* PluginManager::LoadCooperate() 39 { 40 CALL_DEBUG_ENTER; 41 if (!Utility::DoesFileExist(LIB_COOPERATE_PATH.data())) { 42 FI_HILOGE("'%{public}s' does't exist", LIB_COOPERATE_PATH.data()); 43 return nullptr; 44 } 45 std::lock_guard guard(lock_); 46 CHKPP(context_); 47 if (cooperate_ == nullptr) { 48 cooperate_ = LoadLibrary<ICooperate>(context_, LIB_COOPERATE_PATH.data()); 49 } 50 return (cooperate_ != nullptr ? cooperate_->GetInstance() : nullptr); 51 } 52 UnloadCooperate()53void PluginManager::UnloadCooperate() 54 { 55 CALL_DEBUG_ENTER; 56 std::lock_guard guard(lock_); 57 cooperate_.reset(); 58 } 59 LoadMotionDrag()60IMotionDrag* PluginManager::LoadMotionDrag() 61 { 62 CALL_DEBUG_ENTER; 63 if (!Utility::DoesFileExist(LIB_MOTION_DRAG_PATH.data())) { 64 FI_HILOGE("'%{public}s' does't exist", LIB_MOTION_DRAG_PATH.data()); 65 return nullptr; 66 } 67 std::lock_guard guard(lock_); 68 CHKPP(context_); 69 if (motionDrag_ == nullptr) { 70 motionDrag_ = LoadLibrary<IMotionDrag>(context_, LIB_MOTION_DRAG_PATH.data()); 71 } 72 return (motionDrag_ != nullptr ? motionDrag_->GetInstance() : nullptr); 73 } 74 UnloadMotionDrag()75void PluginManager::UnloadMotionDrag() 76 { 77 CALL_DEBUG_ENTER; 78 std::lock_guard guard(lock_); 79 motionDrag_.reset(); 80 } 81 } // namespace DeviceStatus 82 } // namespace Msdp 83 } // namespace OHOS 84