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 
22 #undef LOG_TAG
23 #define LOG_TAG "PluginManager"
24 
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 
29 #if (defined(__aarch64__) || defined(__x86_64__))
30 constexpr std::string_view LIB_COOPERATE_PATH { "/system/lib64/libintention_cooperate.z.so" };
31 #else
32 constexpr std::string_view LIB_COOPERATE_PATH { "/system/lib/libintention_cooperate.z.so" };
33 #endif // defined(__x86_64__)
34 
LoadCooperate()35 ICooperate* PluginManager::LoadCooperate()
36 {
37     CALL_DEBUG_ENTER;
38     std::lock_guard guard(lock_);
39     CHKPP(context_);
40     if (cooperate_ == nullptr) {
41         cooperate_ = LoadLibrary<ICooperate>(context_, LIB_COOPERATE_PATH.data());
42     }
43     return (cooperate_ != nullptr ? cooperate_->GetInstance() : nullptr);
44 }
45 
UnloadCooperate()46 void PluginManager::UnloadCooperate()
47 {
48     CALL_DEBUG_ENTER;
49     std::lock_guard guard(lock_);
50     cooperate_.reset();
51 }
52 } // namespace DeviceStatus
53 } // namespace Msdp
54 } // namespace OHOS
55