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 "session/host/include/atomicservice_basic_engine_plugin.h"
17 #include "window_manager_hilog.h"
18
19 namespace OHOS::Rosen {
20 #ifdef WINDOW_ATOMIC_SERVICE_ATTRIBUTION_ENABLE
AtomicserviceIconInfo()21 AtomicserviceIconInfo::AtomicserviceIconInfo() : bundleName_(""), moduleName_(""), abilityName_(""), circleIcon_(""),
22 eyelashRingIcon_(""), appName_(""), deviceTypes_({}), resizable_(0), supportWindowMode_({})
23 {}
24
GetBundleName() const25 std::string AtomicserviceIconInfo::GetBundleName() const
26 {
27 return bundleName_;
28 }
29
GetModuleName() const30 std::string AtomicserviceIconInfo::GetModuleName() const
31 {
32 return moduleName_;
33 }
34
GetAbilityName() const35 std::string AtomicserviceIconInfo::GetAbilityName() const
36 {
37 return abilityName_;
38 }
39
GetCircleIcon() const40 std::string AtomicserviceIconInfo::GetCircleIcon() const
41 {
42 return circleIcon_;
43 }
44
GetEyelashRingIcon() const45 std::string AtomicserviceIconInfo::GetEyelashRingIcon() const
46 {
47 return eyelashRingIcon_;
48 }
49
GetAppName() const50 std::string AtomicserviceIconInfo::GetAppName() const
51 {
52 return appName_;
53 }
54
GetDeviceTypes() const55 std::vector<std::string> AtomicserviceIconInfo::GetDeviceTypes() const
56 {
57 return deviceTypes_;
58 }
59
GetSupportWindowMode() const60 std::vector<std::string> AtomicserviceIconInfo::GetSupportWindowMode() const
61 {
62 return supportWindowMode_;
63 }
64
GetResizable() const65 int32_t AtomicserviceIconInfo::GetResizable() const
66 {
67 return resizable_;
68 }
69
SetBundleName(const std::string & val)70 void AtomicserviceIconInfo::SetBundleName(const std::string& val)
71 {
72 bundleName_ = val;
73 }
74
SetModuleName(const std::string & val)75 void AtomicserviceIconInfo::SetModuleName(const std::string& val)
76 {
77 moduleName_ = val;
78 }
79
SetAbilityName(const std::string & val)80 void AtomicserviceIconInfo::SetAbilityName(const std::string& val)
81 {
82 abilityName_ = val;
83 }
84
SetCircleIcon(const std::string & val)85 void AtomicserviceIconInfo::SetCircleIcon(const std::string& val)
86 {
87 circleIcon_ = val;
88 }
89
SetEyelashRingIcon(const std::string & val)90 void AtomicserviceIconInfo::SetEyelashRingIcon(const std::string& val)
91 {
92 eyelashRingIcon_ = val;
93 }
94
SetAppName(const std::string & val)95 void AtomicserviceIconInfo::SetAppName(const std::string& val)
96 {
97 appName_ = val;
98 }
99
SetDeviceTypes(const std::vector<std::string> & val)100 void AtomicserviceIconInfo::SetDeviceTypes(const std::vector<std::string>& val)
101 {
102 deviceTypes_ = val;
103 }
104
SetSupportWindowMode(const std::vector<std::string> & val)105 void AtomicserviceIconInfo::SetSupportWindowMode(const std::vector<std::string>& val)
106 {
107 supportWindowMode_ = val;
108 }
109
SetResizable(int32_t val)110 void AtomicserviceIconInfo::SetResizable(int32_t val)
111 {
112 resizable_ = val;
113 }
114
Marshalling(Parcel & parcel) const115 bool AtomicserviceIconInfo::Marshalling(Parcel& parcel) const
116 {
117 return true;
118 }
119
Unmarshalling(Parcel & parcel)120 AtomicserviceIconInfo *AtomicserviceIconInfo::Unmarshalling(Parcel& parcel)
121 {
122 AtomicserviceIconInfo *data = new AtomicserviceIconInfo();
123 return data;
124 }
125
AtomicServiceBasicEnginePlugin()126 AtomicServiceBasicEnginePlugin::AtomicServiceBasicEnginePlugin()
127 {
128 // if ACE_ENGINE_PLUGIN_PATH is defined, load so pack
129 #ifdef ACE_ENGINE_PLUGIN_PATH
130 atomicServiceBasicEngine_ = dlopen(
131 (char*)ACE_ENGINE_PLUGIN_PATH, RTLD_LAZY);
132 if (atomicServiceBasicEngine_ == nullptr) {
133 TLOGW(WmsLogTag::WMS_LIFE,
134 "dlopen lib %{public}s false", (char*)ACE_ENGINE_PLUGIN_PATH);
135 return;
136 }
137 #else
138 TLOGW(WmsLogTag::WMS_LIFE, "ACE_ENGINE_PLUGIN_PATH is not defined");
139 return;
140 #endif
141 // load function GetAtomicserviceIconInfoPlugin
142 getAtomicserviceIconInfoPlugin_ = (GetAtomicserviceIconInfoPlugin*)(dlsym(
143 atomicServiceBasicEngine_, "GetAtomicserviceIconInfoPlugin"));
144 if (getAtomicserviceIconInfoPlugin_ == nullptr) {
145 TLOGW(WmsLogTag::WMS_LIFE,
146 "fail to dlsym GetAtomicserviceIconInfoPlugin, reason: %{public}s", dlerror());
147 return;
148 }
149 // load function FreeData
150 freeData_ = (FreeData*)(dlsym(atomicServiceBasicEngine_, "FreeAtomicserviceIconInfoPlugin"));
151 if (freeData_ == nullptr) {
152 TLOGW(WmsLogTag::WMS_LIFE,
153 "fail to dlsym FreeData, reason: %{public}s", dlerror());
154 return;
155 }
156 }
157
~AtomicServiceBasicEnginePlugin()158 AtomicServiceBasicEnginePlugin::~AtomicServiceBasicEnginePlugin()
159 {
160 // close dlopen so pack
161 if (atomicServiceBasicEngine_ != nullptr) {
162 dlclose(atomicServiceBasicEngine_);
163 atomicServiceBasicEngine_ = nullptr;
164 }
165 ReleaseData();
166 getAtomicserviceIconInfoPlugin_ = nullptr;
167 freeData_ = nullptr;
168 }
169
GetInstance()170 AtomicServiceBasicEnginePlugin& AtomicServiceBasicEnginePlugin::GetInstance()
171 {
172 static AtomicServiceBasicEnginePlugin instance;
173 return instance;
174 }
175
GetParamsFromAtomicServiceBasicEngine(const std::string & bundleName)176 AtomicserviceIconInfo* AtomicServiceBasicEnginePlugin::GetParamsFromAtomicServiceBasicEngine(
177 const std::string& bundleName)
178 {
179 std::lock_guard<std::mutex> lock(mutex_);
180 if (getAtomicserviceIconInfoPlugin_ == nullptr) {
181 TLOGE(WmsLogTag::WMS_LIFE, "getAtomicserviceIconInfoPlugin_ is nullptr");
182 return nullptr;
183 }
184 int32_t ret = getAtomicserviceIconInfoPlugin_(bundleName, &atomicserviceIconInfo_);
185 if (ret != 0) {
186 TLOGE(WmsLogTag::WMS_LIFE, "failed, bundleName:%{public}s", bundleName.c_str());
187 return nullptr;
188 }
189 return atomicserviceIconInfo_;
190 }
191
ReleaseData()192 int32_t AtomicServiceBasicEnginePlugin::ReleaseData()
193 {
194 std::lock_guard<std::mutex> lock(mutex_);
195 // free data
196 if (freeData_ != nullptr && atomicserviceIconInfo_ != nullptr) {
197 freeData_(atomicserviceIconInfo_);
198 atomicserviceIconInfo_ = nullptr;
199 return 0;
200 }
201 TLOGW(WmsLogTag::WMS_LIFE, "dlsym FreeData interface failed, can't release data");
202 return -1;
203 }
204 #endif // WINDOW_ATOMIC_SERVICE_ATTRIBUTION_ENABLE
205 } //namespace OHOS::Rosen
206