1 /*
2 * Copyright (c) 2021-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 "componentloader/component_loader.h"
17
18 #include <cinttypes>
19 #include <dlfcn.h>
20 #include <fstream>
21 #include <string>
22
23 #include "config_policy_utils.h"
24 #include "nlohmann/json.hpp"
25
26 #include "constants.h"
27 #include "dh_context.h"
28 #include "dh_utils_hitrace.h"
29 #include "dh_utils_hisysevent.h"
30 #include "dh_utils_tool.h"
31 #include "hidump_helper.h"
32 #include "distributed_hardware_log.h"
33 #include "version_info.h"
34 #include "version_info_manager.h"
35 #include "version_manager.h"
36
37 using nlohmann::json;
38
39 namespace OHOS {
40 namespace DistributedHardware {
41 #undef DH_LOG_TAG
42 #define DH_LOG_TAG "ComponentLoader"
43
44 IMPLEMENT_SINGLE_INSTANCE(ComponentLoader);
45 using GetHardwareClass = IHardwareHandler *(*)();
46 using GetSourceHardwareClass = IDistributedHardwareSource *(*)();
47 using GetSinkHardwareClass = IDistributedHardwareSink *(*)();
48 namespace {
49 const std::string COMP_NAME = "name";
50 const std::string COMP_TYPE = "type";
51 const std::string COMP_HANDLER_LOC = "comp_handler_loc";
52 const std::string COMP_HANDLER_VERSION = "comp_handler_version";
53 const std::string COMP_SOURCE_LOC = "comp_source_loc";
54 const std::string COMP_SOURCE_VERSION = "comp_source_version";
55 const std::string COMP_SOURCE_SA_ID = "comp_source_sa_id";
56 const std::string COMP_SINK_LOC = "comp_sink_loc";
57 const std::string COMP_SINK_VERSION = "comp_sink_version";
58 const std::string COMP_SINK_SA_ID = "comp_sink_sa_id";
59 const std::string COMP_RESOURCE_DESC = "comp_resource_desc";
60 const std::string COMP_SUBTYPE = "subtype";
61 const std::string COMP_SENSITIVE = "sensitive";
62
63 const std::string COMPONENTSLOAD_DISTRIBUTED_COMPONENTS = "distributed_components";
64
65 const std::string DEFAULT_NAME = "";
66 const std::string DEFAULT_TYPE = "UNKNOWN";
67 const std::string DEFAULT_LOC = "";
68 const int32_t DEFAULT_SA_ID = -1;
69 const std::string DEFAULT_VERSION = "1.0";
70
71 #ifdef __LP64__
72 const std::string LIB_LOAD_PATH = "/system/lib64/";
73 #else
74 const std::string LIB_LOAD_PATH = "/system/lib/";
75 #endif
76
77 std::map<std::string, DHType> g_mapDhTypeName = {
78 { "UNKNOWN", DHType::UNKNOWN },
79 { "CAMERA", DHType::CAMERA },
80 { "AUDIO", DHType::AUDIO },
81 { "SCREEN", DHType::SCREEN },
82 { "GPS", DHType::GPS },
83 { "INPUT", DHType::INPUT },
84 { "HFP", DHType::HFP },
85 { "A2D", DHType::A2D },
86 { "VIRMODEM_AUDIO", DHType::VIRMODEM_AUDIO },
87 };
88 }
89
Init()90 int32_t ComponentLoader::Init()
91 {
92 DHLOGI("start");
93 DHTraceStart(COMPONENT_LOAD_START);
94 int32_t ret = ParseConfig();
95 StoreLocalDHVersionInDB();
96 DHTraceEnd();
97
98 return ret;
99 }
100
GetAllCompTypes()101 std::vector<DHType> ComponentLoader::GetAllCompTypes()
102 {
103 std::vector<DHType> DHTypeALL;
104 for (std::map<DHType, CompHandler>::iterator it = compHandlerMap_.begin(); it != compHandlerMap_.end(); ++it) {
105 DHTypeALL.push_back(it->first);
106 }
107 return DHTypeALL;
108 }
109
ParseComponent(const nlohmann::json & json,CompConfig & cfg)110 int32_t ParseComponent(const nlohmann::json &json, CompConfig &cfg)
111 {
112 if (!IsString(json, COMP_NAME)) {
113 DHLOGE("COMP_NAME is invalid");
114 return ERR_DH_FWK_JSON_PARSE_FAILED;
115 }
116 cfg.name = json.at(COMP_NAME).get<std::string>();
117 if (!IsString(json, COMP_TYPE)) {
118 DHLOGE("COMP_TYPE is invalid");
119 return ERR_DH_FWK_JSON_PARSE_FAILED;
120 }
121 cfg.type = g_mapDhTypeName[json.at(COMP_TYPE).get<std::string>()];
122 if (!IsString(json, COMP_HANDLER_LOC)) {
123 DHLOGE("COMP_HANDLER_LOC is invalid");
124 return ERR_DH_FWK_JSON_PARSE_FAILED;
125 }
126 cfg.compHandlerLoc = json.at(COMP_HANDLER_LOC).get<std::string>();
127 if (!IsString(json, COMP_HANDLER_VERSION)) {
128 DHLOGE("COMP_HANDLER_VERSION is invalid");
129 return ERR_DH_FWK_JSON_PARSE_FAILED;
130 }
131 cfg.compHandlerVersion = json.at(COMP_HANDLER_VERSION).get<std::string>();
132 return DH_FWK_SUCCESS;
133 }
134
ParseSource(const nlohmann::json & json,CompConfig & cfg)135 int32_t ParseSource(const nlohmann::json &json, CompConfig &cfg)
136 {
137 if (!IsString(json, COMP_SOURCE_LOC)) {
138 DHLOGE("COMP_SOURCE_LOC is invalid");
139 return ERR_DH_FWK_JSON_PARSE_FAILED;
140 }
141 cfg.compSourceLoc = json.at(COMP_SOURCE_LOC).get<std::string>();
142 if (!IsString(json, COMP_SOURCE_VERSION)) {
143 DHLOGE("COMP_SOURCE_VERSION is invalid");
144 return ERR_DH_FWK_JSON_PARSE_FAILED;
145 }
146 cfg.compSourceVersion = json.at(COMP_SOURCE_VERSION).get<std::string>();
147 if (!IsInt32(json, COMP_SOURCE_SA_ID)) {
148 DHLOGE("COMP_SOURCE_SA_ID is invalid");
149 return ERR_DH_FWK_JSON_PARSE_FAILED;
150 }
151 cfg.compSourceSaId = json.at(COMP_SOURCE_SA_ID).get<int32_t>();
152 return DH_FWK_SUCCESS;
153 }
154
ParseSink(const nlohmann::json & json,CompConfig & cfg)155 int32_t ParseSink(const nlohmann::json &json, CompConfig &cfg)
156 {
157 if (!IsString(json, COMP_SINK_LOC)) {
158 DHLOGE("COMP_SINK_LOC is invalid");
159 return ERR_DH_FWK_JSON_PARSE_FAILED;
160 }
161 cfg.compSinkLoc = json.at(COMP_SINK_LOC).get<std::string>();
162 if (!IsString(json, COMP_SINK_VERSION)) {
163 DHLOGE("COMP_SINK_VERSION is invalid");
164 return ERR_DH_FWK_JSON_PARSE_FAILED;
165 }
166 cfg.compSinkVersion = json.at(COMP_SINK_VERSION).get<std::string>();
167 if (!IsInt32(json, COMP_SINK_SA_ID)) {
168 DHLOGE("COMP_SINK_SA_ID is invalid");
169 return ERR_DH_FWK_JSON_PARSE_FAILED;
170 }
171 cfg.compSinkSaId = json.at(COMP_SINK_SA_ID).get<int32_t>();
172 return DH_FWK_SUCCESS;
173 }
174
ParseResourceDesc(const nlohmann::json & json,CompConfig & cfg)175 int32_t ParseResourceDesc(const nlohmann::json &json, CompConfig &cfg)
176 {
177 if (!IsArray(json, COMP_RESOURCE_DESC)) {
178 DHLOGE("COMP_RESOURCE_DESC is invalid");
179 return ERR_DH_FWK_JSON_PARSE_FAILED;
180 }
181 for (const auto &obj : json.at(COMP_RESOURCE_DESC)) {
182 ResourceDesc desc;
183 desc.subtype = obj[COMP_SUBTYPE];
184 desc.sensitiveValue = obj[COMP_SENSITIVE];
185 cfg.compResourceDesc.push_back(desc);
186 }
187 return DH_FWK_SUCCESS;
188 }
189
from_json(const nlohmann::json & json,CompConfig & cfg)190 void from_json(const nlohmann::json &json, CompConfig &cfg)
191 {
192 if (ParseComponent(json, cfg) != DH_FWK_SUCCESS) {
193 DHLOGE("ParseComponent is failed");
194 return;
195 }
196 if (ParseSource(json, cfg) != DH_FWK_SUCCESS) {
197 DHLOGE("ParseSource is failed");
198 return;
199 }
200 if (ParseSink(json, cfg) != DH_FWK_SUCCESS) {
201 DHLOGE("ParseSink is failed");
202 return;
203 }
204 if (ParseResourceDesc(json, cfg) != DH_FWK_SUCCESS) {
205 DHLOGE("ParseResourceDesc is failed");
206 return;
207 }
208 }
209
GetCompVersionFromComConfig(const CompConfig & cCfg)210 CompVersion ComponentLoader::GetCompVersionFromComConfig(const CompConfig& cCfg)
211 {
212 CompVersion compVersions;
213 compVersions.dhType = cCfg.type;
214 compVersions.name = cCfg.name;
215 compVersions.handlerVersion = cCfg.compHandlerVersion;
216 compVersions.sinkVersion = cCfg.compSinkVersion;
217 compVersions.sourceVersion = cCfg.compSourceVersion;
218 return compVersions;
219 }
220
GetCompPathAndVersion(const std::string & jsonStr,std::map<DHType,CompConfig> & dhtypeMap)221 int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::map<DHType, CompConfig> &dhtypeMap)
222 {
223 auto jsonCfg = json::parse(jsonStr, nullptr, false);
224 if (jsonCfg.is_discarded()) {
225 DHLOGE("jsonStr parse failed");
226 return ERR_DH_FWK_JSON_PARSE_FAILED;
227 }
228
229 if (jsonCfg.find(COMPONENTSLOAD_DISTRIBUTED_COMPONENTS) == jsonCfg.end()) {
230 DHLOGE("not find distributed_components");
231 return ERR_DH_FWK_PARA_INVALID;
232 }
233
234 std::vector<CompConfig> vecJsnCfg =
235 jsonCfg.at(COMPONENTSLOAD_DISTRIBUTED_COMPONENTS).get<std::vector<CompConfig>>();
236 DHLOGI("get distributed_components CompConfig size is %zu", vecJsnCfg.size());
237 if (vecJsnCfg.size() == 0 || vecJsnCfg.size() > MAX_COMP_SIZE) {
238 DHLOGE("CompConfig size is invalid!");
239 return ERR_DH_FWK_PARA_INVALID;
240 }
241 for (auto iter = vecJsnCfg.begin(); iter != vecJsnCfg.end(); ++iter) {
242 dhtypeMap.insert(std::pair<DHType, CompConfig>((*iter).type, (*iter)));
243 localDHVersion_.compVersions.insert(
244 std::pair<DHType, CompVersion>((*iter).type, GetCompVersionFromComConfig(*iter)));
245 }
246 isLocalVersionInit_.store(true);
247 return DH_FWK_SUCCESS;
248 }
249
GetLocalDHVersion(DHVersion & dhVersion)250 int32_t ComponentLoader::GetLocalDHVersion(DHVersion &dhVersion)
251 {
252 if (!isLocalVersionInit_.load()) {
253 DHLOGE("get local DHVersion fail");
254 return ERR_DH_FWK_LOADER_GET_LOCAL_VERSION_FAIL;
255 }
256 dhVersion = localDHVersion_;
257 return DH_FWK_SUCCESS;
258 }
259
StoreLocalDHVersionInDB()260 void ComponentLoader::StoreLocalDHVersionInDB()
261 {
262 if (!isLocalVersionInit_.load()) {
263 DHLOGE("Store local DHVersion fail");
264 return;
265 }
266 VersionInfo versionInfo;
267 versionInfo.dhVersion = VersionManager::GetInstance().GetLocalDeviceVersion();
268 versionInfo.deviceId = DHContext::GetInstance().GetDeviceInfo().deviceId;
269 versionInfo.compVersions = localDHVersion_.compVersions;
270 VersionInfoManager::GetInstance()->AddVersion(versionInfo);
271 }
272
GetHandler(const std::string & soName)273 void *ComponentLoader::GetHandler(const std::string &soName)
274 {
275 char path[PATH_MAX + 1] = {0x00};
276 if (soName.length() == 0 || (LIB_LOAD_PATH.length() + soName.length()) > PATH_MAX ||
277 realpath((LIB_LOAD_PATH + soName).c_str(), path) == nullptr) {
278 DHLOGE("File canonicalization failed");
279 return nullptr;
280 }
281 void *pHandler = dlopen(path, RTLD_LAZY | RTLD_NODELETE);
282 if (pHandler == nullptr) {
283 DHLOGE("%s handler load failed, failed reason : %s", path, dlerror());
284 HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
285 "dhfwk so open failed, soname : " + soName);
286 return nullptr;
287 }
288 return pHandler;
289 }
290
GetAllHandler(std::map<DHType,CompConfig> & dhtypeMap)291 void ComponentLoader::GetAllHandler(std::map<DHType, CompConfig> &dhtypeMap)
292 {
293 std::map<DHType, CompConfig>::iterator itor;
294 for (itor = dhtypeMap.begin(); itor != dhtypeMap.end(); ++itor) {
295 CompHandler comHandler;
296 comHandler.type = itor->second.type;
297 comHandler.hardwareHandler = GetHandler(itor->second.compHandlerLoc);
298 comHandler.sourceHandler = GetHandler(itor->second.compSourceLoc);
299 comHandler.sourceSaId = itor->second.compSourceSaId;
300 comHandler.sinkHandler = GetHandler(itor->second.compSinkLoc);
301 comHandler.sinkSaId = itor->second.compSinkSaId;
302 std::vector<ResourceDesc> compResourceDesc = itor->second.compResourceDesc;
303 for (auto it = compResourceDesc.begin(); it != compResourceDesc.end(); it++) {
304 resDescMap_[it->subtype] = it->sensitiveValue;
305 }
306 comHandler.resourceDesc = itor->second.compResourceDesc;
307 compHandlerMap_[itor->second.type] = comHandler;
308 }
309 }
310
GetHardwareHandler(const DHType dhType,IHardwareHandler * & hardwareHandlerPtr)311 int32_t ComponentLoader::GetHardwareHandler(const DHType dhType, IHardwareHandler *&hardwareHandlerPtr)
312 {
313 if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) {
314 DHLOGE("DHType not exist, dhType: %" PRIu32, (uint32_t)dhType);
315 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
316 }
317
318 if (compHandlerMap_[dhType].hardwareHandler == nullptr) {
319 DHLOGE("hardwareHandler is null.");
320 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
321 }
322
323 GetHardwareClass getHardwareClassHandler = (GetHardwareClass)dlsym(compHandlerMap_[dhType].hardwareHandler,
324 COMPONENT_LOADER_GET_HARDWARE_HANDLER.c_str());
325 if (getHardwareClassHandler == nullptr) {
326 DHLOGE("get getHardwareClassHandler is null, failed reason : %s", dlerror());
327 dlclose(compHandlerMap_[dhType].hardwareHandler);
328 compHandlerMap_[dhType].hardwareHandler = nullptr;
329 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
330 }
331 hardwareHandlerPtr = getHardwareClassHandler();
332 return DH_FWK_SUCCESS;
333 }
334
GetSource(const DHType dhType,IDistributedHardwareSource * & sourcePtr)335 int32_t ComponentLoader::GetSource(const DHType dhType, IDistributedHardwareSource *&sourcePtr)
336 {
337 if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) {
338 DHLOGE("DHType not exist, dhType: %" PRIu32, (uint32_t)dhType);
339 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
340 }
341
342 if (compHandlerMap_[dhType].sourceHandler == nullptr) {
343 DHLOGE("sourceHandler is null.");
344 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
345 }
346
347 GetSourceHardwareClass getSourceHardClassHandler = (GetSourceHardwareClass)dlsym(
348 compHandlerMap_[dhType].sourceHandler, COMPONENT_LOADER_GET_SOURCE_HANDLER.c_str());
349 if (getSourceHardClassHandler == nullptr) {
350 DHLOGE("get getSourceHardClassHandler is null, failed reason : %s", dlerror());
351 dlclose(compHandlerMap_[dhType].sourceHandler);
352 compHandlerMap_[dhType].sourceHandler = nullptr;
353 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
354 }
355 sourcePtr = getSourceHardClassHandler();
356 return DH_FWK_SUCCESS;
357 }
358
GetSink(const DHType dhType,IDistributedHardwareSink * & sinkPtr)359 int32_t ComponentLoader::GetSink(const DHType dhType, IDistributedHardwareSink *&sinkPtr)
360 {
361 if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) {
362 DHLOGE("DHType not exist, dhType: %" PRIu32, (uint32_t)dhType);
363 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
364 }
365
366 if (compHandlerMap_[dhType].sinkHandler == nullptr) {
367 DHLOGE("sinkHandler is null.");
368 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
369 }
370
371 GetSinkHardwareClass getSinkHardwareClassHandler =
372 (GetSinkHardwareClass)dlsym(compHandlerMap_[dhType].sinkHandler, COMPONENT_LOADER_GET_SINK_HANDLER.c_str());
373 if (getSinkHardwareClassHandler == nullptr) {
374 DHLOGE("get getSinkHardwareClassHandler is null, failed reason : %s", dlerror());
375 dlclose(compHandlerMap_[dhType].sinkHandler);
376 compHandlerMap_[dhType].sinkHandler = nullptr;
377 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
378 }
379 sinkPtr = getSinkHardwareClassHandler();
380 return DH_FWK_SUCCESS;
381 }
382
Readfile(const std::string & filePath)383 std::string ComponentLoader::Readfile(const std::string &filePath)
384 {
385 std::ifstream infile;
386 std::string sLine;
387 std::string sAll = "";
388 infile.open(filePath);
389 if (!infile.is_open()) {
390 DHLOGE("filePath: %s Readfile fail", filePath.c_str());
391 return sAll;
392 }
393
394 while (getline(infile, sLine)) {
395 sAll.append(sLine);
396 }
397 infile.close();
398 return sAll;
399 }
400
ParseConfig()401 int32_t ComponentLoader::ParseConfig()
402 {
403 std::map<DHType, CompConfig> dhtypeMap;
404 int32_t ret;
405 DHLOGI("ParseConfig start");
406 char buf[MAX_PATH_LEN] = {0};
407 char path[PATH_MAX + 1] = {0x00};
408 char *profilePath = GetOneCfgFile(COMPONENTSLOAD_PROFILE_PATH, buf, MAX_PATH_LEN);
409 if (profilePath == nullptr) {
410 DHLOGE("profilePath is null.");
411 return ERR_DH_FWK_LOADER_PROFILE_PATH_IS_NULL;
412 }
413 if (strlen(profilePath) == 0 || strlen(profilePath) > PATH_MAX || realpath(profilePath, path) == nullptr) {
414 DHLOGE("File connicailization failed.");
415 return ERR_DH_FWK_LOADER_PROFILE_PATH_IS_NULL;
416 }
417 std::string componentProfilePath(path);
418 std::string jsonStr = Readfile(componentProfilePath);
419 if (jsonStr.length() == 0 || jsonStr.size() > MAX_MESSAGE_LEN) {
420 DHLOGE("ConfigJson size is invalid!");
421 return ERR_DH_FWK_LOADER_CONFIG_JSON_INVALID;
422 }
423 ret = GetCompPathAndVersion(jsonStr, dhtypeMap);
424 if (ret != DH_FWK_SUCCESS) {
425 return ret;
426 }
427 GetAllHandler(dhtypeMap);
428 return DH_FWK_SUCCESS;
429 }
430
ReleaseHandler(void * & handler)431 int32_t ComponentLoader::ReleaseHandler(void *&handler)
432 {
433 if (handler == nullptr) {
434 DHLOGE("handler is null.");
435 return ERR_DH_FWK_LOADER_HANDLER_IS_NULL;
436 }
437
438 if (dlclose(handler) != 0) {
439 DHLOGE("dlclose failed.");
440 return ERR_DH_FWK_LOADER_DLCLOSE_FAIL;
441 }
442 handler = nullptr;
443 return DH_FWK_SUCCESS;
444 }
445
UnInit()446 int32_t ComponentLoader::UnInit()
447 {
448 DHLOGI("release all handler");
449 DHTraceStart(COMPONENT_RELEASE_START);
450 int32_t ret = DH_FWK_SUCCESS;
451 for (std::map<DHType, CompHandler>::iterator iter = compHandlerMap_.begin();
452 iter != compHandlerMap_.end(); ++iter) {
453 ret += ReleaseHardwareHandler(iter->first);
454 ret += ReleaseSource(iter->first);
455 ret += ReleaseSink(iter->first);
456 }
457 compHandlerMap_.clear();
458 resDescMap_.clear();
459 DHTraceEnd();
460 return ret;
461 }
462
ReleaseHardwareHandler(const DHType dhType)463 int32_t ComponentLoader::ReleaseHardwareHandler(const DHType dhType)
464 {
465 if (!IsDHTypeExist(dhType)) {
466 return ERR_DH_FWK_TYPE_NOT_EXIST;
467 }
468 int32_t ret = ReleaseHandler(compHandlerMap_[dhType].hardwareHandler);
469 if (ret) {
470 DHLOGE("fail, dhType: %#X", dhType);
471 HiSysEventWriteReleaseMsg(DHFWK_RELEASE_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
472 dhType, ret, "dhfwk release hardware handler failed.");
473 }
474 return ret;
475 }
476
ReleaseSource(const DHType dhType)477 int32_t ComponentLoader::ReleaseSource(const DHType dhType)
478 {
479 if (!IsDHTypeExist(dhType)) {
480 return ERR_DH_FWK_TYPE_NOT_EXIST;
481 }
482 int32_t ret = ReleaseHandler(compHandlerMap_[dhType].sourceHandler);
483 if (ret) {
484 DHLOGE("fail, dhType: %#X", dhType);
485 HiSysEventWriteReleaseMsg(DHFWK_RELEASE_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
486 dhType, ret, "dhfwk release source failed.");
487 }
488 return ret;
489 }
490
ReleaseSink(const DHType dhType)491 int32_t ComponentLoader::ReleaseSink(const DHType dhType)
492 {
493 if (!IsDHTypeExist(dhType)) {
494 return ERR_DH_FWK_TYPE_NOT_EXIST;
495 }
496 int32_t ret = ReleaseHandler(compHandlerMap_[dhType].sinkHandler);
497 if (ret) {
498 DHLOGE("fail, dhType: %#X", dhType);
499 HiSysEventWriteReleaseMsg(DHFWK_RELEASE_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
500 dhType, ret, "dhfwk release sink failed.");
501 }
502 return ret;
503 }
504
IsDHTypeExist(DHType dhType)505 bool ComponentLoader::IsDHTypeExist(DHType dhType)
506 {
507 if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) {
508 DHLOGE("fail, dhType: %#X not exist", dhType);
509 return false;
510 }
511 return true;
512 }
513
GetSourceSaId(const DHType dhType)514 int32_t ComponentLoader::GetSourceSaId(const DHType dhType)
515 {
516 if (compHandlerMap_.find(dhType) == compHandlerMap_.end()) {
517 DHLOGE("DHType not exist, dhType: %" PRIu32, (uint32_t)dhType);
518 return DEFAULT_SA_ID;
519 }
520 return compHandlerMap_[dhType].sourceSaId;
521 }
522
GetDHTypeBySrcSaId(const int32_t saId)523 DHType ComponentLoader::GetDHTypeBySrcSaId(const int32_t saId)
524 {
525 DHType type = DHType::UNKNOWN;
526 for (const auto &handler : compHandlerMap_) {
527 if (handler.second.sourceSaId == saId) {
528 type = handler.second.type;
529 break;
530 }
531 }
532 return type;
533 }
534
GetCompResourceDesc()535 std::map<std::string, bool> ComponentLoader::GetCompResourceDesc()
536 {
537 return resDescMap_;
538 }
539 } // namespace DistributedHardware
540 } // namespace OHOS
541