• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_mgr_host_impl.h"
17 
18 #include <future>
19 
20 #include "json_serializer.h"
21 #include "app_log_wrapper.h"
22 #include "bundle_mgr_service.h"
23 #include "bundle_util.h"
24 #include "bundle_parser.h"
25 #include "installd_client.h"
26 #include "bundle_permission_mgr.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 
GetApplicationInfo(const std::string & appName,const ApplicationFlag flag,const int userId,ApplicationInfo & appInfo)31 bool BundleMgrHostImpl::GetApplicationInfo(
32     const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo)
33 {
34     auto dataMgr = GetDataMgrFromService();
35     if (dataMgr == nullptr) {
36         APP_LOGE("DataMgr is nullptr");
37         return false;
38     }
39     return dataMgr->GetApplicationInfo(appName, flag, userId, appInfo);
40 }
41 
GetApplicationInfos(const ApplicationFlag flag,const int userId,std::vector<ApplicationInfo> & appInfos)42 bool BundleMgrHostImpl::GetApplicationInfos(
43     const ApplicationFlag flag, const int userId, std::vector<ApplicationInfo> &appInfos)
44 {
45     auto dataMgr = GetDataMgrFromService();
46     if (dataMgr == nullptr) {
47         APP_LOGE("DataMgr is nullptr");
48         return false;
49     }
50     return dataMgr->GetApplicationInfos(flag, userId, appInfos);
51 }
52 
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo)53 bool BundleMgrHostImpl::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo)
54 {
55     auto dataMgr = GetDataMgrFromService();
56     if (dataMgr == nullptr) {
57         APP_LOGE("DataMgr is nullptr");
58         return false;
59     }
60     return dataMgr->GetBundleInfo(bundleName, flag, bundleInfo);
61 }
62 
GetBundleInfos(const BundleFlag flag,std::vector<BundleInfo> & bundleInfos)63 bool BundleMgrHostImpl::GetBundleInfos(const BundleFlag flag, std::vector<BundleInfo> &bundleInfos)
64 {
65     auto dataMgr = GetDataMgrFromService();
66     if (dataMgr == nullptr) {
67         APP_LOGE("DataMgr is nullptr");
68         return false;
69     }
70     return dataMgr->GetBundleInfos(flag, bundleInfos);
71 }
72 
GetBundleNameForUid(const int uid,std::string & bundleName)73 bool BundleMgrHostImpl::GetBundleNameForUid(const int uid, std::string &bundleName)
74 {
75     auto dataMgr = GetDataMgrFromService();
76     if (dataMgr == nullptr) {
77         APP_LOGE("DataMgr is nullptr");
78         return false;
79     }
80     return dataMgr->GetBundleNameForUid(uid, bundleName);
81 }
82 
GetBundlesForUid(const int uid,std::vector<std::string> & bundleNames)83 bool BundleMgrHostImpl::GetBundlesForUid(const int uid, std::vector<std::string> &bundleNames)
84 {
85     auto dataMgr = GetDataMgrFromService();
86     if (dataMgr == nullptr) {
87         APP_LOGE("DataMgr is nullptr");
88         return false;
89     }
90     return dataMgr->GetBundlesForUid(uid, bundleNames);
91 }
92 
GetNameForUid(const int uid,std::string & name)93 bool BundleMgrHostImpl::GetNameForUid(const int uid, std::string &name)
94 {
95     auto dataMgr = GetDataMgrFromService();
96     if (dataMgr == nullptr) {
97         APP_LOGE("DataMgr is nullptr");
98         return false;
99     }
100     return dataMgr->GetNameForUid(uid, name);
101 }
102 
GetBundleGids(const std::string & bundleName,std::vector<int> & gids)103 bool BundleMgrHostImpl::GetBundleGids(const std::string &bundleName, std::vector<int> &gids)
104 {
105     auto dataMgr = GetDataMgrFromService();
106     if (dataMgr == nullptr) {
107         APP_LOGE("DataMgr is nullptr");
108         return false;
109     }
110     return dataMgr->GetBundleGids(bundleName, gids);
111 }
112 
CheckIsSystemAppByUid(const int uid)113 bool BundleMgrHostImpl::CheckIsSystemAppByUid(const int uid)
114 {
115     auto dataMgr = GetDataMgrFromService();
116     if (dataMgr == nullptr) {
117         APP_LOGE("DataMgr is nullptr");
118         return false;
119     }
120     return dataMgr->CheckIsSystemAppByUid(uid);
121 }
122 
GetBundleInfosByMetaData(const std::string & metaData,std::vector<BundleInfo> & bundleInfos)123 bool BundleMgrHostImpl::GetBundleInfosByMetaData(const std::string &metaData, std::vector<BundleInfo> &bundleInfos)
124 {
125     auto dataMgr = GetDataMgrFromService();
126     if (dataMgr == nullptr) {
127         APP_LOGE("DataMgr is nullptr");
128         return false;
129     }
130     return dataMgr->GetBundleInfosByMetaData(metaData, bundleInfos);
131 }
132 
QueryAbilityInfo(const Want & want,AbilityInfo & abilityInfo)133 bool BundleMgrHostImpl::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo)
134 {
135     auto dataMgr = GetDataMgrFromService();
136     if (dataMgr == nullptr) {
137         APP_LOGE("DataMgr is nullptr");
138         return false;
139     }
140     return dataMgr->QueryAbilityInfo(want, abilityInfo);
141 }
142 
QueryAbilityInfos(const Want & want,std::vector<AbilityInfo> & abilityInfos)143 bool BundleMgrHostImpl::QueryAbilityInfos(const Want &want, std::vector<AbilityInfo> &abilityInfos)
144 {
145     auto dataMgr = GetDataMgrFromService();
146     if (dataMgr == nullptr) {
147         APP_LOGE("DataMgr is nullptr");
148         return false;
149     }
150     return dataMgr->QueryAbilityInfos(want, abilityInfos);
151 }
152 
QueryAbilityInfoByUri(const std::string & abilityUri,AbilityInfo & abilityInfo)153 bool BundleMgrHostImpl::QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo)
154 {
155     auto dataMgr = GetDataMgrFromService();
156     if (dataMgr == nullptr) {
157         APP_LOGE("DataMgr is nullptr");
158         return false;
159     }
160     return dataMgr->QueryAbilityInfoByUri(abilityUri, abilityInfo);
161 }
162 
QueryKeepAliveBundleInfos(std::vector<BundleInfo> & bundleInfos)163 bool BundleMgrHostImpl::QueryKeepAliveBundleInfos(std::vector<BundleInfo> &bundleInfos)
164 {
165     auto dataMgr = GetDataMgrFromService();
166     if (dataMgr == nullptr) {
167         APP_LOGE("DataMgr is nullptr");
168         return false;
169     }
170     return dataMgr->QueryKeepAliveBundleInfos(bundleInfos);
171 }
172 
GetAbilityLabel(const std::string & bundleName,const std::string & className)173 std::string BundleMgrHostImpl::GetAbilityLabel(const std::string &bundleName, const std::string &className)
174 {
175     auto dataMgr = GetDataMgrFromService();
176     if (dataMgr == nullptr) {
177         APP_LOGE("DataMgr is nullptr");
178         return Constants::EMPTY_STRING;
179     }
180     return dataMgr->GetAbilityLabel(bundleName, className);
181 }
182 
GetBundleArchiveInfo(const std::string & hapFilePath,const BundleFlag flag,BundleInfo & bundleInfo)183 bool BundleMgrHostImpl::GetBundleArchiveInfo(
184     const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo)
185 {
186     std::string realPath;
187     auto ret = BundleUtil::CheckFilePath(hapFilePath, realPath);
188     if (ret != ERR_OK) {
189         APP_LOGE("GetBundleArchiveInfo file path %{public}s invalid", hapFilePath.c_str());
190         return false;
191     }
192     InnerBundleInfo info;
193     BundleParser bundleParser;
194     ret = bundleParser.Parse(realPath, info);
195     if (ret != ERR_OK) {
196         APP_LOGE("parse bundle info failed, error: %{public}d", ret);
197         return false;
198     }
199     info.GetBundleInfo(flag, bundleInfo);
200     return true;
201 }
202 
GetHapModuleInfo(const AbilityInfo & abilityInfo,HapModuleInfo & hapModuleInfo)203 bool BundleMgrHostImpl::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)
204 {
205     if (abilityInfo.bundleName.empty() || abilityInfo.package.empty()) {
206         APP_LOGE("fail to GetHapModuleInfo due to params empty");
207         return false;
208     }
209     auto dataMgr = GetDataMgrFromService();
210     if (dataMgr == nullptr) {
211         APP_LOGE("DataMgr is nullptr");
212         return false;
213     }
214     return dataMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo);
215 }
216 
GetLaunchWantForBundle(const std::string & bundleName,Want & want)217 bool BundleMgrHostImpl::GetLaunchWantForBundle(const std::string &bundleName, Want &want)
218 {
219     auto dataMgr = GetDataMgrFromService();
220     if (dataMgr == nullptr) {
221         APP_LOGE("DataMgr is nullptr");
222         return false;
223     }
224     return dataMgr->GetLaunchWantForBundle(bundleName, want);
225 }
226 
CheckPublicKeys(const std::string & firstBundleName,const std::string & secondBundleName)227 int BundleMgrHostImpl::CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName)
228 {
229     auto dataMgr = GetDataMgrFromService();
230     if (dataMgr == nullptr) {
231         APP_LOGE("DataMgr is nullptr");
232         return false;
233     }
234     return dataMgr->CheckPublicKeys(firstBundleName, secondBundleName);
235 }
236 
CheckPermission(const std::string & bundleName,const std::string & permission)237 int BundleMgrHostImpl::CheckPermission(const std::string &bundleName, const std::string &permission)
238 {
239     if (bundleName.empty() || permission.empty()) {
240         APP_LOGE("fail to CheckPermission due to params empty");
241         return Constants::PERMISSION_NOT_GRANTED;
242     }
243     return BundlePermissionMgr::VerifyPermission(bundleName, permission, Constants::DEFAULT_USERID);
244 }
245 
GetPermissionDef(const std::string & permissionName,PermissionDef & permissionDef)246 bool BundleMgrHostImpl::GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef)
247 {
248     if (permissionName.empty()) {
249         APP_LOGE("fail to GetPermissionDef due to params empty");
250         return false;
251     }
252     return BundlePermissionMgr::GetPermissionDef(permissionName, permissionDef);
253 }
254 
GetAllPermissionGroupDefs(std::vector<PermissionDef> & permissionDefs)255 bool BundleMgrHostImpl::GetAllPermissionGroupDefs(std::vector<PermissionDef> &permissionDefs)
256 {
257     return true;
258 }
259 
GetAppsGrantedPermissions(const std::vector<std::string> & permissions,std::vector<std::string> & appNames)260 bool BundleMgrHostImpl::GetAppsGrantedPermissions(
261     const std::vector<std::string> &permissions, std::vector<std::string> &appNames)
262 {
263     return true;
264 }
265 
HasSystemCapability(const std::string & capName)266 bool BundleMgrHostImpl::HasSystemCapability(const std::string &capName)
267 {
268     return true;
269 }
270 
GetSystemAvailableCapabilities(std::vector<std::string> & systemCaps)271 bool BundleMgrHostImpl::GetSystemAvailableCapabilities(std::vector<std::string> &systemCaps)
272 {
273     return true;
274 }
275 
IsSafeMode()276 bool BundleMgrHostImpl::IsSafeMode()
277 {
278     return true;
279 }
280 
CleanBundleCacheFiles(const std::string & bundleName,const sptr<ICleanCacheCallback> & cleanCacheCallback)281 bool BundleMgrHostImpl::CleanBundleCacheFiles(
282     const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback)
283 {
284     if (!cleanCacheCallback || bundleName.empty()) {
285         APP_LOGE("the cleanCacheCallback is nullptr or bundleName empty");
286         return false;
287     }
288     ApplicationInfo applicationInfo;
289     if (!GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, 0, applicationInfo)) {
290         APP_LOGE("can not get application info of %{public}s", bundleName.c_str());
291         return false;
292     }
293     auto cacheDir = applicationInfo.cacheDir;
294     std::thread([cacheDir, cleanCacheCallback]() {
295         auto ret = InstalldClient::GetInstance()->CleanBundleDataDir(cacheDir);
296         cleanCacheCallback->OnCleanCacheFinished((ret == ERR_OK) ? true : false);
297     }).detach();
298     return true;
299 }
300 
CleanBundleDataFiles(const std::string & bundleName)301 bool BundleMgrHostImpl::CleanBundleDataFiles(const std::string &bundleName)
302 {
303     if (bundleName.empty()) {
304         APP_LOGE("the  bundleName empty");
305         return false;
306     }
307     ApplicationInfo applicationInfo;
308     if (!GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, 0, applicationInfo)) {
309         APP_LOGE("can not get application info of %{public}s", bundleName.c_str());
310         return false;
311     }
312     if (InstalldClient::GetInstance()->CleanBundleDataDir(applicationInfo.dataDir) != ERR_OK) {
313         return false;
314     }
315     return true;
316 }
317 
RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> & bundleStatusCallback)318 bool BundleMgrHostImpl::RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
319 {
320     if ((!bundleStatusCallback) || (bundleStatusCallback->GetBundleName().empty())) {
321         APP_LOGE("the bundleStatusCallback is nullptr or bundleName empty");
322         return false;
323     }
324     auto dataMgr = GetDataMgrFromService();
325     if (dataMgr == nullptr) {
326         APP_LOGE("DataMgr is nullptr");
327         return false;
328     }
329     return dataMgr->RegisterBundleStatusCallback(bundleStatusCallback);
330 }
331 
ClearBundleStatusCallback(const sptr<IBundleStatusCallback> & bundleStatusCallback)332 bool BundleMgrHostImpl::ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
333 {
334     if (!bundleStatusCallback) {
335         APP_LOGE("the bundleStatusCallback is nullptr");
336         return false;
337     }
338     auto dataMgr = GetDataMgrFromService();
339     if (dataMgr == nullptr) {
340         APP_LOGE("DataMgr is nullptr");
341         return false;
342     }
343     return dataMgr->ClearBundleStatusCallback(bundleStatusCallback);
344 }
345 
UnregisterBundleStatusCallback()346 bool BundleMgrHostImpl::UnregisterBundleStatusCallback()
347 {
348     auto dataMgr = GetDataMgrFromService();
349     if (dataMgr == nullptr) {
350         APP_LOGE("DataMgr is nullptr");
351         return false;
352     }
353     return dataMgr->UnregisterBundleStatusCallback();
354 }
355 
DumpInfos(const DumpFlag flag,const std::string & bundleName,std::string & result)356 bool BundleMgrHostImpl::DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result)
357 {
358     auto dataMgr = GetDataMgrFromService();
359     if (dataMgr == nullptr) {
360         APP_LOGE("DataMgr is nullptr");
361         return false;
362     }
363     bool ret = false;
364     switch (flag) {
365         case DumpFlag::DUMP_BUNDLE_LIST: {
366             std::vector<std::string> bundleNames;
367             ret = dataMgr->GetBundleList(bundleNames);
368             if (ret) {
369                 for (const auto &name : bundleNames) {
370                     result.append(name);
371                     result.append("\n");
372                 }
373                 APP_LOGI("get installed bundles success");
374             }
375             break;
376         }
377         case DumpFlag::DUMP_ALL_BUNDLE_INFO: {
378             std::vector<BundleInfo> bundleInfos;
379             ret = GetBundleInfos(BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfos);
380             if (ret) {
381                 for (const auto &info : bundleInfos) {
382                     result.append(info.name);
383                     result.append(":\n");
384                     nlohmann::json jsonObject = info;
385                     result.append(jsonObject.dump(Constants::DUMP_INDENT));
386                     result.append("\n");
387                 }
388                 APP_LOGI("get all bundle info success");
389             }
390             break;
391         }
392         case DumpFlag::DUMP_BUNDLE_INFO: {
393             BundleInfo bundleInfo;
394             ret = GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo);
395             if (ret) {
396                 result.append(bundleName);
397                 result.append(":\n");
398                 nlohmann::json jsonObject = bundleInfo;
399                 result.append(jsonObject.dump(Constants::DUMP_INDENT));
400                 result.append("\n");
401                 APP_LOGI("get %{public}s bundle info success", bundleName.c_str());
402             }
403             break;
404         }
405         default:
406             APP_LOGE("dump flag error");
407             return false;
408     }
409     return ret;
410 }
411 
IsApplicationEnabled(const std::string & bundleName)412 bool BundleMgrHostImpl::IsApplicationEnabled(const std::string &bundleName)
413 {
414     auto dataMgr = GetDataMgrFromService();
415     if (dataMgr == nullptr) {
416         APP_LOGE("DataMgr is nullptr");
417         return false;
418     }
419     return dataMgr->IsApplicationEnabled(bundleName);
420 }
421 
SetApplicationEnabled(const std::string & bundleName,bool isEnable)422 bool BundleMgrHostImpl::SetApplicationEnabled(const std::string &bundleName, bool isEnable)
423 {
424     auto dataMgr = GetDataMgrFromService();
425     if (dataMgr == nullptr) {
426         APP_LOGE("DataMgr is nullptr");
427         return false;
428     }
429     return dataMgr->SetApplicationEnabled(bundleName, isEnable);
430 }
431 
IsAbilityEnabled(const AbilityInfo & abilityInfo)432 bool BundleMgrHostImpl::IsAbilityEnabled(const AbilityInfo &abilityInfo)
433 {
434     auto dataMgr = GetDataMgrFromService();
435     if (dataMgr == nullptr) {
436         APP_LOGE("DataMgr is nullptr");
437         return false;
438     }
439     return dataMgr->IsAbilityEnabled(abilityInfo);
440 }
441 
SetAbilityEnabled(const AbilityInfo & abilityInfo,bool isEnabled)442 bool BundleMgrHostImpl::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled)
443 {
444     auto dataMgr = GetDataMgrFromService();
445     if (dataMgr == nullptr) {
446         APP_LOGE("DataMgr is nullptr");
447         return false;
448     }
449     return dataMgr->SetAbilityEnabled(abilityInfo, isEnabled);
450 }
451 
GetAbilityIcon(const std::string & bundleName,const std::string & className)452 std::string BundleMgrHostImpl::GetAbilityIcon(const std::string &bundleName, const std::string &className)
453 {
454     auto dataMgr = GetDataMgrFromService();
455     if (dataMgr == nullptr) {
456         APP_LOGE("DataMgr is nullptr");
457         return Constants::EMPTY_STRING;
458     }
459     return dataMgr->GetAbilityIcon(bundleName, className);
460 }
461 
GetBundleInstaller()462 sptr<IBundleInstaller> BundleMgrHostImpl::GetBundleInstaller()
463 {
464     return DelayedSingleton<BundleMgrService>::GetInstance()->GetBundleInstaller();
465 }
466 
CanRequestPermission(const std::string & bundleName,const std::string & permissionName,const int userId)467 bool BundleMgrHostImpl::CanRequestPermission(
468     const std::string &bundleName, const std::string &permissionName, const int userId)
469 {
470     if (bundleName.empty() || permissionName.empty()) {
471         APP_LOGE("fail to CanRequestPermission due to params empty");
472         return false;
473     }
474     return BundlePermissionMgr::CanRequestPermission(bundleName, permissionName, userId);
475 }
476 
RequestPermissionFromUser(const std::string & bundleName,const std::string & permissionName,const int userId)477 bool BundleMgrHostImpl::RequestPermissionFromUser(
478     const std::string &bundleName, const std::string &permissionName, const int userId)
479 {
480     if (bundleName.empty() || permissionName.empty()) {
481         APP_LOGE("fail to CanRequestPermission due to params empty");
482         return false;
483     }
484     bool ret = BundlePermissionMgr::RequestPermissionFromUser(bundleName, permissionName, userId);
485     // send Permissions Changed event
486     APP_LOGI("send Permissions Changed event");
487     BundleInfo info;
488     bool ret_getInfo = GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, info);
489     APP_LOGI("ret_getInfo = %{public}d", ret_getInfo);
490     if (ret && ret_getInfo) {
491         Want want;
492         want.SetAction("PERMISSIONS_CHANGED_EVENT");
493         EventFwk::CommonEventData commonData;
494         commonData.SetWant(want);
495         commonData.SetCode(info.uid);
496         EventFwk::CommonEventManager::PublishCommonEvent(commonData);
497     }
498     return ret;
499 }
500 
RegisterAllPermissionsChanged(const sptr<OnPermissionChangedCallback> & callback)501 bool BundleMgrHostImpl::RegisterAllPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
502 {
503     auto dataMgr = GetDataMgrFromService();
504     if (dataMgr == nullptr) {
505         APP_LOGE("DataMgr is nullptr");
506         return false;
507     }
508     return dataMgr->RegisterAllPermissionsChanged(callback);
509 }
510 
RegisterPermissionsChanged(const std::vector<int> & uids,const sptr<OnPermissionChangedCallback> & callback)511 bool BundleMgrHostImpl::RegisterPermissionsChanged(
512     const std::vector<int> &uids, const sptr<OnPermissionChangedCallback> &callback)
513 {
514     auto dataMgr = GetDataMgrFromService();
515     if (dataMgr == nullptr) {
516         APP_LOGE("DataMgr is nullptr");
517         return false;
518     }
519     return dataMgr->RegisterPermissionsChanged(uids, callback);
520 }
521 
UnregisterPermissionsChanged(const sptr<OnPermissionChangedCallback> & callback)522 bool BundleMgrHostImpl::UnregisterPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
523 {
524     auto dataMgr = GetDataMgrFromService();
525     if (dataMgr == nullptr) {
526         APP_LOGE("DataMgr is nullptr");
527         return false;
528     }
529     return dataMgr->UnregisterPermissionsChanged(callback);
530 }
531 
GetAllFormsInfo(std::vector<FormInfo> & formInfos)532 bool BundleMgrHostImpl::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
533 {
534     auto dataMgr = GetDataMgrFromService();
535     if (dataMgr == nullptr) {
536         APP_LOGE("DataMgr is nullptr");
537         return false;
538     }
539     return dataMgr->GetAllFormsInfo(formInfos);
540 }
541 
GetFormsInfoByApp(const std::string & bundleName,std::vector<FormInfo> & formInfos)542 bool BundleMgrHostImpl::GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos)
543 {
544     auto dataMgr = GetDataMgrFromService();
545     if (dataMgr == nullptr) {
546         APP_LOGE("DataMgr is nullptr");
547         return false;
548     }
549     return dataMgr->GetFormsInfoByApp(bundleName, formInfos);
550 }
551 
GetFormsInfoByModule(const std::string & bundleName,const std::string & moduleName,std::vector<FormInfo> & formInfos)552 bool BundleMgrHostImpl::GetFormsInfoByModule(
553     const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos)
554 {
555     auto dataMgr = GetDataMgrFromService();
556     if (dataMgr == nullptr) {
557         APP_LOGE("DataMgr is nullptr");
558         return false;
559     }
560     return dataMgr->GetFormsInfoByModule(bundleName, moduleName, formInfos);
561 }
562 
GetShortcutInfos(const std::string & bundleName,std::vector<ShortcutInfo> & shortcutInfos)563 bool BundleMgrHostImpl::GetShortcutInfos(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos)
564 {
565     auto dataMgr = GetDataMgrFromService();
566     if (dataMgr == nullptr) {
567         APP_LOGE("DataMgr is nullptr");
568         return false;
569     }
570     return dataMgr->GetShortcutInfos(bundleName, shortcutInfos);
571 }
572 
GetModuleUsageRecords(const int32_t number,std::vector<ModuleUsageRecord> & moduleUsageRecords)573 bool BundleMgrHostImpl::GetModuleUsageRecords(const int32_t number, std::vector<ModuleUsageRecord> &moduleUsageRecords)
574 {
575     auto dataMgr = GetDataMgrFromService();
576     if (dataMgr == nullptr) {
577         APP_LOGE("DataMgr is nullptr");
578         return false;
579     }
580     return dataMgr->GetUsageRecords(number, moduleUsageRecords);
581 }
582 
NotifyActivityLifeStatus(const std::string & bundleName,const std::string & abilityName,const int64_t launchTime)583 bool BundleMgrHostImpl::NotifyActivityLifeStatus(
584     const std::string &bundleName, const std::string &abilityName, const int64_t launchTime)
585 {
586     APP_LOGI("NotifyActivityLifeStatus begin");
587     std::thread([this, bundleName, abilityName, launchTime]() {
588         auto dataMgr = GetDataMgrFromService();
589         dataMgr->NotifyActivityLifeStatus(bundleName, abilityName, launchTime);
590     }).detach();
591     APP_LOGI("NotifyActivityLifeStatus end");
592     return true;
593 }
594 
GetDataMgrFromService()595 const std::shared_ptr<BundleDataMgr> BundleMgrHostImpl::GetDataMgrFromService()
596 {
597     return DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
598 }
599 
600 }  // namespace AppExecFwk
601 }  // namespace OHOS
602