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 "bundle_resource_process.h"
17
18 #include "account_helper.h"
19 #include "bundle_mgr_service.h"
20 #include "bundle_resource_parser.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
24 namespace {
25 constexpr const char* INNER_UNDER_LINE = "_";
26 }
27
GetBundleResourceInfo(const InnerBundleInfo & innerBundleInfo,const int32_t userId,ResourceInfo & resourceInfo)28 bool BundleResourceProcess::GetBundleResourceInfo(const InnerBundleInfo &innerBundleInfo,
29 const int32_t userId,
30 ResourceInfo &resourceInfo)
31 {
32 if (innerBundleInfo.GetBundleName().empty()) {
33 APP_LOGE("bundleName is empty");
34 return false;
35 }
36 if (innerBundleInfo.GetApplicationBundleType() == BundleType::SHARED) {
37 APP_LOGD("bundleName:%{public}s is shared", innerBundleInfo.GetBundleName().c_str());
38 return false;
39 }
40 resourceInfo = ConvertToBundleResourceInfo(innerBundleInfo);
41 // process overlay hap paths
42 GetOverlayModuleHapPaths(innerBundleInfo, resourceInfo.moduleName_, userId, resourceInfo.overlayHapPaths_);
43 return true;
44 }
45
GetAllResourceInfo(const int32_t userId,std::map<std::string,std::vector<ResourceInfo>> & resourceInfosMap)46 bool BundleResourceProcess::GetAllResourceInfo(
47 const int32_t userId,
48 std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap)
49 {
50 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
51 if (dataMgr == nullptr) {
52 APP_LOGE("dataMgr is nullptr");
53 return false;
54 }
55 if (!dataMgr->HasUserId(userId)) {
56 APP_LOGE("userId %{public}d not exist", userId);
57 return false;
58 }
59 std::vector<std::string> allBundleNames = dataMgr->GetAllBundleName();
60 if (allBundleNames.empty()) {
61 APP_LOGE("bundleInfos is empty");
62 return false;
63 }
64
65 for (const auto &bundleName : allBundleNames) {
66 InnerBundleInfo innerBundleInfo;
67 if (!dataMgr->FetchInnerBundleInfo(bundleName, innerBundleInfo)) {
68 APP_LOGE("bundleName %{public}s not exist", bundleName.c_str());
69 continue;
70 }
71 if (innerBundleInfo.GetApplicationBundleType() == BundleType::SHARED) {
72 APP_LOGD("bundleName:%{public}s is shared", bundleName.c_str());
73 continue;
74 }
75 std::vector<ResourceInfo> resourceInfos;
76 if (!InnerGetResourceInfo(innerBundleInfo, userId, resourceInfos) || resourceInfos.empty()) {
77 APP_LOGW("%{public}s resourceInfo empty", bundleName.c_str());
78 } else {
79 resourceInfosMap[bundleName] = resourceInfos;
80 }
81 }
82 APP_LOGI("resourceInfosMap size: %{public}zu", resourceInfosMap.size());
83 return true;
84 }
85
GetResourceInfoByBundleName(const std::string & bundleName,const int32_t userId,std::vector<ResourceInfo> & resourceInfo)86 bool BundleResourceProcess::GetResourceInfoByBundleName(
87 const std::string &bundleName,
88 const int32_t userId,
89 std::vector<ResourceInfo> &resourceInfo)
90 {
91 APP_LOGD("start, bundleName:%{public}s", bundleName.c_str());
92 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
93 if (dataMgr == nullptr) {
94 APP_LOGE("dataMgr is nullptr");
95 return false;
96 }
97 if (!dataMgr->HasUserId(userId)) {
98 APP_LOGE("userId %{public}d not exist", userId);
99 return false;
100 }
101 InnerBundleInfo innerBundleInfo;
102 if (!dataMgr->FetchInnerBundleInfo(bundleName, innerBundleInfo)) {
103 APP_LOGE("bundleName %{public}s not exist", bundleName.c_str());
104 return false;
105 }
106
107 return InnerGetResourceInfo(innerBundleInfo, userId, resourceInfo);
108 }
109
GetLauncherResourceInfoByAbilityName(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const int32_t userId,ResourceInfo & resourceInfo)110 bool BundleResourceProcess::GetLauncherResourceInfoByAbilityName(
111 const std::string &bundleName,
112 const std::string &moduleName,
113 const std::string &abilityName,
114 const int32_t userId,
115 ResourceInfo &resourceInfo)
116 {
117 APP_LOGD("start, bundleName:%{public}s, moduleName:%{public}s, abilityName:%{public}s",
118 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
119 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
120 if (dataMgr == nullptr) {
121 APP_LOGE("dataMgr is nullptr");
122 return false;
123 }
124 if (!dataMgr->HasUserId(userId)) {
125 APP_LOGE("userId %{public}d not exist", userId);
126 return false;
127 }
128 InnerBundleInfo innerBundleInfo;
129 if (!dataMgr->FetchInnerBundleInfo(bundleName, innerBundleInfo)) {
130 APP_LOGE("bundleName %{public}s not exist", bundleName.c_str());
131 return false;
132 }
133
134 std::vector<ResourceInfo> resourceInfos;
135 if (GetAbilityResourceInfos(innerBundleInfo, userId, resourceInfos)) {
136 for (const auto &info : resourceInfos) {
137 if ((info.moduleName_ == moduleName) && (info.abilityName_ == abilityName)) {
138 resourceInfo = info;
139 return true;
140 }
141 }
142 }
143 APP_LOGE("bundleName %{public}s, moduleName %{public}s, abilityName %{public}s not exist",
144 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
145 return false;
146 }
147
GetResourceInfoByColorModeChanged(const std::vector<std::string> & resourceNames,const int32_t userId,std::vector<ResourceInfo> & resourceInfos)148 bool BundleResourceProcess::GetResourceInfoByColorModeChanged(
149 const std::vector<std::string> &resourceNames,
150 const int32_t userId,
151 std::vector<ResourceInfo> &resourceInfos)
152 {
153 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
154 if (dataMgr == nullptr) {
155 APP_LOGE("dataMgr is nullptr");
156 return false;
157 }
158 const std::map<std::string, InnerBundleInfo> bundleInfos = dataMgr->GetAllInnerBundleInfos();
159 std::vector<std::string> bundleNames;
160 for (const auto &item : bundleInfos) {
161 bundleNames.emplace_back(item.first);
162 InnerBundleUserInfo innerBundleUserInfo;
163 if (item.second.GetInnerBundleUserInfo(userId, innerBundleUserInfo) &&
164 !innerBundleUserInfo.cloneInfos.empty()) {
165 // need process clone app resource
166 APP_LOGI("bundleName:%{public}s has clone info", item.first.c_str());
167 for (const auto &clone : innerBundleUserInfo.cloneInfos) {
168 bundleNames.emplace_back(std::to_string(clone.second.appIndex) + INNER_UNDER_LINE + item.first);
169 }
170 }
171 }
172 std::set<std::string> needAddResourceBundles;
173 for (const auto &bundleName : bundleNames) {
174 if (std::find(resourceNames.begin(), resourceNames.end(), bundleName) == resourceNames.end()) {
175 ResourceInfo info;
176 info.ParseKey(bundleName);
177 needAddResourceBundles.insert(info.bundleName_);
178 }
179 }
180 if (needAddResourceBundles.empty()) {
181 APP_LOGW("needAddResourceBundles is empty");
182 return true;
183 }
184
185 for (const auto &bundleName : needAddResourceBundles) {
186 if (!GetResourceInfoByBundleName(bundleName, userId, resourceInfos)) {
187 APP_LOGW("bundleName %{public}s GetResourceInfoByBundleName failed", bundleName.c_str());
188 }
189 }
190 return true;
191 }
192
ChangeDynamicIcon(std::vector<ResourceInfo> & resourceInfos,const ResourceInfo & resourceInfo)193 void BundleResourceProcess::ChangeDynamicIcon(
194 std::vector<ResourceInfo> &resourceInfos, const ResourceInfo &resourceInfo)
195 {
196 for (auto &info : resourceInfos) {
197 info.icon_ = resourceInfo.icon_;
198 info.foreground_ = resourceInfo.foreground_;
199 info.background_ = resourceInfo.background_;
200 info.iconNeedParse_ = false;
201 }
202 }
203
GetDynamicIcon(const InnerBundleInfo & innerBundleInfo,ResourceInfo & resourceInfo)204 bool BundleResourceProcess::GetDynamicIcon(
205 const InnerBundleInfo &innerBundleInfo, ResourceInfo &resourceInfo)
206 {
207 std::string curDynamicIconModule = innerBundleInfo.GetCurDynamicIconModule();
208 if (curDynamicIconModule.empty()) {
209 return false;
210 }
211
212 std::map<std::string, ExtendResourceInfo> extResourceInfos =
213 innerBundleInfo.GetExtendResourceInfos();
214 auto iter = extResourceInfos.find(curDynamicIconModule);
215 if (iter == extResourceInfos.end()) {
216 APP_LOGE("Module not exist %{public}s",
217 curDynamicIconModule.c_str());
218 return false;
219 }
220 auto &extendResourceInfo = iter->second;
221 BundleResourceParser parser;
222 if (parser.ParseIconResourceByPath(extendResourceInfo.filePath, extendResourceInfo.iconId, resourceInfo)) {
223 APP_LOGE("bundleName:%{public}s parse dynamicIcon failed, iconId:%{public}d",
224 innerBundleInfo.GetBundleName().c_str(), extendResourceInfo.iconId);
225 return false;
226 }
227 return true;
228 }
229
InnerGetResourceInfo(const InnerBundleInfo & innerBundleInfo,const int32_t userId,std::vector<ResourceInfo> & resourceInfos)230 bool BundleResourceProcess::InnerGetResourceInfo(
231 const InnerBundleInfo &innerBundleInfo,
232 const int32_t userId,
233 std::vector<ResourceInfo> &resourceInfos)
234 {
235 ResourceInfo dynamicResourceInfo;
236 bool hasDynamicIcon = GetDynamicIcon(innerBundleInfo, dynamicResourceInfo);
237 if (!OnGetResourceInfo(innerBundleInfo, userId, resourceInfos)) {
238 if (!hasDynamicIcon) {
239 APP_LOGW("bundleName: %{public}s get bundle resource failed",
240 innerBundleInfo.GetBundleName().c_str());
241 return false;
242 }
243
244 APP_LOGI("%{public}s no default icon, build new", innerBundleInfo.GetBundleName().c_str());
245 ResourceInfo defaultResourceInfo;
246 defaultResourceInfo.bundleName_ = innerBundleInfo.GetBundleName();
247 defaultResourceInfo.labelNeedParse_ = false;
248 defaultResourceInfo.iconNeedParse_ = false;
249 defaultResourceInfo.icon_ = dynamicResourceInfo.icon_;
250 defaultResourceInfo.foreground_ = dynamicResourceInfo.foreground_;
251 defaultResourceInfo.background_ = dynamicResourceInfo.background_;
252 resourceInfos.emplace_back(defaultResourceInfo);
253 }
254
255 if (hasDynamicIcon) {
256 APP_LOGI("bundle %{public}s has dynamicIcon", innerBundleInfo.GetBundleName().c_str());
257 ChangeDynamicIcon(resourceInfos, dynamicResourceInfo);
258 }
259 // for clone bundle
260 std::set<int32_t> appIndexes = innerBundleInfo.GetCloneBundleAppIndexes();
261 if (!appIndexes.empty()) {
262 APP_LOGI("bundleName:%{public}s contains clone bundle", innerBundleInfo.GetBundleName().c_str());
263 std::vector<int32_t> indexes(appIndexes.begin(), appIndexes.end());
264 for (auto &info : resourceInfos) {
265 info.appIndexes_ = indexes;
266 }
267 }
268 return true;
269 }
270
OnGetResourceInfo(const InnerBundleInfo & innerBundleInfo,const int32_t userId,std::vector<ResourceInfo> & resourceInfos)271 bool BundleResourceProcess::OnGetResourceInfo(
272 const InnerBundleInfo &innerBundleInfo,
273 const int32_t userId,
274 std::vector<ResourceInfo> &resourceInfos)
275 {
276 std::string bundleName = innerBundleInfo.GetBundleName();
277 APP_LOGD("start, bundleName:%{public}s", bundleName.c_str());
278 // get bundle
279 ResourceInfo bundleResourceInfo;
280 if (!GetBundleResourceInfo(innerBundleInfo, userId, bundleResourceInfo)) {
281 APP_LOGW("%{public}s get resource failed", bundleName.c_str());
282 return false;
283 }
284 resourceInfos.push_back(bundleResourceInfo);
285
286 // get ability
287 std::vector<ResourceInfo> abilityResourceInfos;
288 if (GetAbilityResourceInfos(innerBundleInfo, userId, abilityResourceInfos)) {
289 for (const auto &info : abilityResourceInfos) {
290 resourceInfos.push_back(info);
291 }
292 }
293 APP_LOGI_NOFUNC("OnGetResourceInfo -n %{public}s size:%{public}d", bundleName.c_str(),
294 static_cast<int32_t>(resourceInfos.size()));
295 return !resourceInfos.empty();
296 }
297
ConvertToLauncherAbilityResourceInfo(const AbilityInfo & info)298 ResourceInfo BundleResourceProcess::ConvertToLauncherAbilityResourceInfo(const AbilityInfo &info)
299 {
300 ResourceInfo resourceInfo;
301 resourceInfo.bundleName_ = info.bundleName;
302 resourceInfo.moduleName_ = info.moduleName;
303 resourceInfo.abilityName_ = info.name;
304 resourceInfo.labelId_ = info.labelId;
305 resourceInfo.iconId_ = info.iconId;
306 resourceInfo.hapPath_ = info.hapPath;
307 return resourceInfo;
308 }
309
ConvertToBundleResourceInfo(const InnerBundleInfo & innerBundleInfo)310 ResourceInfo BundleResourceProcess::ConvertToBundleResourceInfo(const InnerBundleInfo &innerBundleInfo)
311 {
312 ApplicationInfo appInfo = innerBundleInfo.GetBaseApplicationInfo();
313 innerBundleInfo.AdaptMainLauncherResourceInfo(appInfo);
314 ResourceInfo resourceInfo;
315 resourceInfo.bundleName_ = innerBundleInfo.GetBundleName();
316 resourceInfo.labelId_ = appInfo.labelResource.id;
317 resourceInfo.iconId_ = appInfo.iconResource.id;
318 const auto &moduleName = appInfo.labelResource.moduleName;
319 const auto &moduleInfos = innerBundleInfo.GetInnerModuleInfos();
320 for (const auto &iter : moduleInfos) {
321 if (iter.second.moduleName == moduleName) {
322 resourceInfo.hapPath_ = iter.second.hapPath;
323 break;
324 }
325 }
326 resourceInfo.moduleName_ = moduleName;
327 resourceInfo.abilityName_ = std::string();
328 return resourceInfo;
329 }
330
GetLauncherAbilityResourceInfos(const InnerBundleInfo & innerBundleInfo,const int32_t userId,std::vector<ResourceInfo> & resourceInfos)331 bool BundleResourceProcess::GetLauncherAbilityResourceInfos(
332 const InnerBundleInfo &innerBundleInfo,
333 const int32_t userId,
334 std::vector<ResourceInfo> &resourceInfos)
335 {
336 APP_LOGD("start get ability, bundleName:%{public}s", innerBundleInfo.GetBundleName().c_str());
337 if (!CheckIsNeedProcessAbilityResource(innerBundleInfo)) {
338 APP_LOGW("%{public}s no need add ability resource", innerBundleInfo.GetBundleName().c_str());
339 return false;
340 }
341
342 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
343 if (dataMgr == nullptr) {
344 APP_LOGE("dataMgr is nullptr");
345 return false;
346 }
347 OHOS::AAFwk::Want want;
348 want.SetAction(Want::ACTION_HOME);
349 want.AddEntity(Want::ENTITY_HOME);
350 std::vector<AbilityInfo> abilityInfos;
351 int64_t time = 0;
352 dataMgr->GetMatchLauncherAbilityInfos(want, innerBundleInfo, abilityInfos, time, userId);
353
354 if (abilityInfos.empty()) {
355 APP_LOGW("%{public}s no launcher ability Info", innerBundleInfo.GetBundleName().c_str());
356 return false;
357 }
358 for (const auto &info : abilityInfos) {
359 resourceInfos.push_back(ConvertToLauncherAbilityResourceInfo(info));
360 }
361 // process overlay hap paths
362 size_t size = resourceInfos.size();
363 for (size_t index = 0; index < size; ++index) {
364 if ((index > 0) && (resourceInfos[index].moduleName_ == resourceInfos[index - 1].moduleName_)) {
365 resourceInfos[index].overlayHapPaths_ = resourceInfos[index - 1].overlayHapPaths_;
366 continue;
367 }
368 GetOverlayModuleHapPaths(innerBundleInfo, resourceInfos[index].moduleName_,
369 userId, resourceInfos[index].overlayHapPaths_);
370 }
371
372 APP_LOGD("end get ability, size:%{public}zu, bundleName:%{public}s", resourceInfos.size(),
373 innerBundleInfo.GetBundleName().c_str());
374 return !resourceInfos.empty();
375 }
376
CheckIsNeedProcessAbilityResource(const InnerBundleInfo & innerBundleInfo)377 bool BundleResourceProcess::CheckIsNeedProcessAbilityResource(const InnerBundleInfo &innerBundleInfo)
378 {
379 if (innerBundleInfo.GetBundleName().empty()) {
380 APP_LOGE("bundleName is empty");
381 return false;
382 }
383 if (innerBundleInfo.GetApplicationBundleType() == BundleType::SHARED) {
384 APP_LOGD("bundleName:%{public}s is shared", innerBundleInfo.GetBundleName().c_str());
385 return false;
386 }
387 if (innerBundleInfo.GetBaseApplicationInfo().hideDesktopIcon) {
388 APP_LOGD("bundleName:%{public}s hide desktop icon", innerBundleInfo.GetBundleName().c_str());
389 return false;
390 }
391 if (innerBundleInfo.GetBaseBundleInfo().entryInstallationFree) {
392 APP_LOGD("bundleName:%{public}s is atomic service, hide desktop icon",
393 innerBundleInfo.GetBundleName().c_str());
394 return false;
395 }
396 return true;
397 }
398
GetOverlayModuleHapPaths(const InnerBundleInfo & innerBundleInfo,const std::string & moduleName,int32_t userId,std::vector<std::string> & overlayHapPaths)399 bool BundleResourceProcess::GetOverlayModuleHapPaths(
400 const InnerBundleInfo &innerBundleInfo,
401 const std::string &moduleName,
402 int32_t userId,
403 std::vector<std::string> &overlayHapPaths)
404 {
405 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
406 auto innerModuleInfo = innerBundleInfo.GetInnerModuleInfoByModuleName(moduleName);
407 if (innerModuleInfo == std::nullopt) {
408 APP_LOGE("moduleName %{public}s not exist", moduleName.c_str());
409 return false;
410 }
411 if (innerModuleInfo->overlayModuleInfo.empty()) {
412 APP_LOGD("moduleName:%{public}s has no overlay module", moduleName.c_str());
413 return false;
414 }
415 std::string bundleName = innerBundleInfo.GetBundleName();
416 APP_LOGI("bundleName %{public}s need add path", bundleName.c_str());
417 auto overlayModuleInfos = innerModuleInfo->overlayModuleInfo;
418 for (auto &info : overlayModuleInfos) {
419 if (info.bundleName == bundleName) {
420 innerBundleInfo.GetOverlayModuleState(info.moduleName, userId, info.state);
421 } else {
422 GetExternalOverlayHapState(info.bundleName, info.moduleName, userId, info.state);
423 }
424 }
425 // sort by priority
426 std::sort(overlayModuleInfos.begin(), overlayModuleInfos.end(),
427 [](const OverlayModuleInfo &lhs, const OverlayModuleInfo &rhs) -> bool {
428 return lhs.priority > rhs.priority;
429 });
430 for (const auto &info : overlayModuleInfos) {
431 if (info.state == OverlayState::OVERLAY_ENABLE) {
432 overlayHapPaths.emplace_back(info.hapPath);
433 }
434 }
435 if (overlayHapPaths.empty()) {
436 APP_LOGE("moduleName %{public}s overlay hap path empty", moduleName.c_str());
437 return false;
438 }
439 return true;
440 #endif
441 return true;
442 }
443
GetExternalOverlayHapState(const std::string & bundleName,const std::string & moduleName,const int32_t userId,int32_t & state)444 bool BundleResourceProcess::GetExternalOverlayHapState(const std::string &bundleName,
445 const std::string &moduleName, const int32_t userId, int32_t &state)
446 {
447 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
448 APP_LOGD("bundleName:%{public}s, moduleName:%{public}s get overlay state", bundleName.c_str(), moduleName.c_str());
449 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
450 if (dataMgr == nullptr) {
451 APP_LOGE("dataMgr is nullptr");
452 return false;
453 }
454 InnerBundleInfo bundleInfo;
455 if (!dataMgr->QueryOverlayInnerBundleInfo(bundleName, bundleInfo)) {
456 return false;
457 }
458 if (!bundleInfo.GetOverlayModuleState(moduleName, userId, state)) {
459 return false;
460 }
461 return true;
462 #endif
463 return true;
464 }
465
GetAbilityResourceInfos(const InnerBundleInfo & innerBundleInfo,const int32_t userId,std::vector<ResourceInfo> & resourceInfos)466 bool BundleResourceProcess::GetAbilityResourceInfos(
467 const InnerBundleInfo &innerBundleInfo,
468 const int32_t userId,
469 std::vector<ResourceInfo> &resourceInfos)
470 {
471 APP_LOGD("start get ability, bundleName:%{public}s", innerBundleInfo.GetBundleName().c_str());
472 if (innerBundleInfo.GetBundleName().empty()) {
473 APP_LOGE("bundleName is empty");
474 return false;
475 }
476 if (innerBundleInfo.GetApplicationBundleType() == BundleType::SHARED) {
477 APP_LOGW("bundleName:%{public}s is shared bundle, no ability", innerBundleInfo.GetBundleName().c_str());
478 return false;
479 }
480 std::map<std::string, AbilityInfo> abilityInfos = innerBundleInfo.GetInnerAbilityInfos();
481 for (const auto &item : abilityInfos) {
482 resourceInfos.emplace_back(ConvertToLauncherAbilityResourceInfo(item.second));
483 }
484 // process overlay hap paths
485 size_t size = resourceInfos.size();
486 for (size_t index = 0; index < size; ++index) {
487 if ((index > 0) && (resourceInfos[index].moduleName_ == resourceInfos[index - 1].moduleName_)) {
488 resourceInfos[index].overlayHapPaths_ = resourceInfos[index - 1].overlayHapPaths_;
489 continue;
490 }
491 GetOverlayModuleHapPaths(innerBundleInfo, resourceInfos[index].moduleName_,
492 userId, resourceInfos[index].overlayHapPaths_);
493 }
494
495 APP_LOGD("end get ability, size:%{public}zu, bundleName:%{public}s", resourceInfos.size(),
496 innerBundleInfo.GetBundleName().c_str());
497 return !resourceInfos.empty();
498 }
499
GetTargetBundleName(const std::string & bundleName,std::string & targetBundleName)500 void BundleResourceProcess::GetTargetBundleName(const std::string &bundleName,
501 std::string &targetBundleName)
502 {
503 targetBundleName = bundleName;
504 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
505 if (dataMgr == nullptr) {
506 APP_LOGE("dataMgr is nullptr");
507 return;
508 }
509 InnerBundleInfo bundleInfo;
510 if (!dataMgr->QueryOverlayInnerBundleInfo(bundleName, bundleInfo)) {
511 return;
512 }
513 if (bundleInfo.GetOverlayType() == OverlayType::OVERLAY_EXTERNAL_BUNDLE) {
514 targetBundleName = bundleInfo.GetTargetBundleName();
515 }
516 }
517 } // AppExecFwk
518 } // OHOS
519