1 /*
2 * Copyright (c) 2023-2024 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_helper.h"
17
18 #include "bundle_mgr_service_death_recipient.h"
19 #include "global_constant.h"
20 #include "hilog_tag_wrapper.h"
21 #include "hitrace_meter.h"
22 #include "iservice_registry.h"
23 #include "system_ability_definition.h"
24 #include "app_utils.h"
25 #include "record_cost_time_util.h"
26
27 namespace OHOS {
28 using AAFwk::RecordCostTimeUtil;
29 namespace AppExecFwk {
30 namespace {
SetAbilityProcessEmpty(AbilityInfo & abilityInfo)31 void SetAbilityProcessEmpty(AbilityInfo &abilityInfo)
32 {
33 if (!AAFwk::AppUtils::GetInstance().IsMultiProcessModel() && abilityInfo.isStageBasedModel) {
34 abilityInfo.process = "";
35 }
36 }
37 }
BundleMgrHelper()38 BundleMgrHelper::BundleMgrHelper() {}
39
~BundleMgrHelper()40 BundleMgrHelper::~BundleMgrHelper()
41 {
42 if (bundleMgr_ != nullptr && bundleMgr_->AsObject() != nullptr && deathRecipient_ != nullptr) {
43 bundleMgr_->AsObject()->RemoveDeathRecipient(deathRecipient_);
44 }
45 }
46
PreConnect()47 void BundleMgrHelper::PreConnect()
48 {
49 Connect(false);
50 }
51
GetNameForUid(const int32_t uid,std::string & name)52 ErrCode BundleMgrHelper::GetNameForUid(const int32_t uid, std::string &name)
53 {
54 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
55 auto bundleMgr = Connect();
56 if (bundleMgr == nullptr) {
57 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
58 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
59 }
60
61 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
62 return bundleMgr->GetNameForUid(uid, name);
63 }
64
GetNameAndIndexForUid(const int32_t uid,std::string & bundleName,int32_t & appIndex)65 ErrCode BundleMgrHelper::GetNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex)
66 {
67 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
68 auto bundleMgr = Connect();
69 if (bundleMgr == nullptr) {
70 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
71 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
72 }
73
74 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
75 return bundleMgr->GetNameAndIndexForUid(uid, bundleName, appIndex);
76 }
77
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)78 bool BundleMgrHelper::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo,
79 int32_t userId)
80 {
81 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
82 auto bundleMgr = Connect();
83 if (bundleMgr == nullptr) {
84 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
85 return false;
86 }
87
88 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
89 return bundleMgr->GetBundleInfo(bundleName, flag, bundleInfo, userId);
90 }
91
InstallSandboxApp(const std::string & bundleName,int32_t dlpType,int32_t userId,int32_t & appIndex)92 ErrCode BundleMgrHelper::InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId,
93 int32_t &appIndex)
94 {
95 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
96 if (bundleName.empty()) {
97 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "empty bundleName");
98 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
99 }
100 auto bundleInstaller = ConnectBundleInstaller();
101 if (bundleInstaller == nullptr) {
102 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleInstaller");
103 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
104 }
105
106 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
107 return bundleInstaller->InstallSandboxApp(bundleName, dlpType, userId, appIndex);
108 }
109
UninstallSandboxApp(const std::string & bundleName,int32_t appIndex,int32_t userId)110 ErrCode BundleMgrHelper::UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId)
111 {
112 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
113 if (bundleName.empty() || appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
114 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "invalid params");
115 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
116 }
117 auto bundleInstaller = ConnectBundleInstaller();
118 if (bundleInstaller == nullptr) {
119 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleInstaller");
120 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
121 }
122
123 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
124 return bundleInstaller->UninstallSandboxApp(bundleName, appIndex, userId);
125 }
126
GetUninstalledBundleInfo(const std::string bundleName,BundleInfo & bundleInfo)127 ErrCode BundleMgrHelper::GetUninstalledBundleInfo(const std::string bundleName, BundleInfo &bundleInfo)
128 {
129 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
130 auto bundleMgr = Connect();
131 if (bundleMgr == nullptr) {
132 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
133 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
134 }
135
136 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
137 return bundleMgr->GetUninstalledBundleInfo(bundleName, bundleInfo);
138 }
139
GetSandboxBundleInfo(const std::string & bundleName,int32_t appIndex,int32_t userId,BundleInfo & info)140 ErrCode BundleMgrHelper::GetSandboxBundleInfo(
141 const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info)
142 {
143 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
144 if (bundleName.empty() || appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
145 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "invalid params");
146 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
147 }
148 auto bundleMgr = Connect();
149 if (bundleMgr == nullptr) {
150 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
151 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
152 }
153
154 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
155 return bundleMgr->GetSandboxBundleInfo(bundleName, appIndex, userId, info);
156 }
157
GetSandboxAbilityInfo(const Want & want,int32_t appIndex,int32_t flags,int32_t userId,AbilityInfo & abilityInfo)158 ErrCode BundleMgrHelper::GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId,
159 AbilityInfo &abilityInfo)
160 {
161 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
162 if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
163 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "invalid params");
164 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
165 }
166 auto bundleMgr = Connect();
167 if (bundleMgr == nullptr) {
168 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
169 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
170 }
171
172 AAFwk::Want newWant = want;
173 newWant.RemoveAllFd();
174
175 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
176 auto ret = bundleMgr->GetSandboxAbilityInfo(newWant, appIndex, flags, userId, abilityInfo);
177 SetAbilityProcessEmpty(abilityInfo);
178 return ret;
179 }
180
GetSandboxExtAbilityInfos(const Want & want,int32_t appIndex,int32_t flags,int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)181 ErrCode BundleMgrHelper::GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags,
182 int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
183 {
184 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
185 if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
186 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "invalid params");
187 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
188 }
189 auto bundleMgr = Connect();
190 if (bundleMgr == nullptr) {
191 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
192 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
193 }
194
195 RecordCostTimeUtil("GetSandboxExtAbilityInfos");
196 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
197 return bundleMgr->GetSandboxExtAbilityInfos(want, appIndex, flags, userId, extensionInfos);
198 }
199
GetSandboxHapModuleInfo(const AbilityInfo & abilityInfo,int32_t appIndex,int32_t userId,HapModuleInfo & hapModuleInfo)200 ErrCode BundleMgrHelper::GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
201 HapModuleInfo &hapModuleInfo)
202 {
203 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
204 if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
205 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "invalid params");
206 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
207 }
208 auto bundleMgr = Connect();
209 if (bundleMgr == nullptr) {
210 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
211 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
212 }
213
214 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
215 return bundleMgr->GetSandboxHapModuleInfo(abilityInfo, appIndex, userId, hapModuleInfo);
216 }
217
GetAppIdByBundleName(const std::string & bundleName,const int32_t userId)218 std::string BundleMgrHelper::GetAppIdByBundleName(const std::string &bundleName, const int32_t userId)
219 {
220 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "GetAppIdByBundleName called");
221 auto bundleMgr = Connect();
222 if (bundleMgr == nullptr) {
223 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
224 return "";
225 }
226
227 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
228 return bundleMgr->GetAppIdByBundleName(bundleName, userId);
229 }
230
ConnectTillSuccess()231 void BundleMgrHelper::ConnectTillSuccess()
232 {
233 while (Connect(false) == nullptr) {
234 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null connect");
235 usleep(REPOLL_TIME_MICRO_SECONDS);
236 }
237 }
238
Connect()239 sptr<IBundleMgr> BundleMgrHelper::Connect()
240 {
241 return Connect(true);
242 }
243
Connect(bool checkBmsReady)244 sptr<IBundleMgr> BundleMgrHelper::Connect(bool checkBmsReady)
245 {
246 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
247 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
248 std::lock_guard<std::mutex> lock(mutex_);
249 if (bundleMgr_ == nullptr) {
250 if (checkBmsReady && !bmsReady_) {
251 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Bms not ready");
252 return nullptr;
253 }
254 sptr<ISystemAbilityManager> systemAbilityManager =
255 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
256 if (systemAbilityManager == nullptr) {
257 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null systemAbilityManager");
258 return nullptr;
259 }
260
261 sptr<IRemoteObject> remoteObject_ = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
262 if (remoteObject_ == nullptr || (bundleMgr_ = iface_cast<IBundleMgr>(remoteObject_)) == nullptr) {
263 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null remoteObject_ or bundleMgr_");
264 return nullptr;
265 }
266 bmsReady_ = true;
267 std::weak_ptr<BundleMgrHelper> weakPtr = shared_from_this();
268 auto deathCallback = [weakPtr](const wptr<IRemoteObject>& object) {
269 auto sharedPtr = weakPtr.lock();
270 if (sharedPtr == nullptr) {
271 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null sharedPtr");
272 return;
273 }
274 sharedPtr->OnDeath();
275 };
276 deathRecipient_ = new (std::nothrow) BundleMgrServiceDeathRecipient(deathCallback);
277 if (deathRecipient_ == nullptr) {
278 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null deathRecipient_");
279 return nullptr;
280 }
281 if (bundleMgr_->AsObject() != nullptr) {
282 bundleMgr_->AsObject()->AddDeathRecipient(deathRecipient_);
283 }
284 }
285
286 return bundleMgr_;
287 }
288
SetBmsReady(bool bmsReady)289 void BundleMgrHelper::SetBmsReady(bool bmsReady)
290 {
291 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "SetBmsReady:%{public}d", bmsReady);
292 std::lock_guard<std::mutex> lock(mutex_);
293 bmsReady_ = bmsReady;
294 }
295
ConnectBundleInstaller()296 sptr<IBundleInstaller> BundleMgrHelper::ConnectBundleInstaller()
297 {
298 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
299 {
300 std::lock_guard<std::mutex> lock(mutex_);
301 if (bundleInstaller_ != nullptr) {
302 return bundleInstaller_;
303 }
304 }
305
306 auto bundleMgr = Connect();
307 if (bundleMgr == nullptr) {
308 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
309 return nullptr;
310 }
311 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
312 std::lock_guard<std::mutex> lock(mutex_);
313 bundleInstaller_ = bundleMgr->GetBundleInstaller();
314 if ((bundleInstaller_ == nullptr) || (bundleInstaller_->AsObject() == nullptr)) {
315 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleInstaller");
316 return nullptr;
317 }
318
319 return bundleInstaller_;
320 }
321
OnDeath()322 void BundleMgrHelper::OnDeath()
323 {
324 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
325 std::lock_guard<std::mutex> lock(mutex_);
326 if (bundleMgr_ == nullptr || bundleMgr_->AsObject() == nullptr) {
327 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr_");
328 return;
329 }
330 bundleMgr_->AsObject()->RemoveDeathRecipient(deathRecipient_);
331 bundleMgr_ = nullptr;
332 bundleInstaller_ = nullptr;
333 }
334
GetBundleInfo(const std::string & bundleName,int32_t flags,BundleInfo & bundleInfo,int32_t userId)335 bool BundleMgrHelper::GetBundleInfo(const std::string &bundleName, int32_t flags,
336 BundleInfo &bundleInfo, int32_t userId)
337 {
338 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
339 auto bundleMgr = Connect();
340 if (bundleMgr == nullptr) {
341 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
342 return false;
343 }
344
345 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
346 return bundleMgr->GetBundleInfo(bundleName, flags, bundleInfo, userId);
347 }
348
GetHapModuleInfo(const AbilityInfo & abilityInfo,HapModuleInfo & hapModuleInfo)349 bool BundleMgrHelper::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)
350 {
351 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
352 auto bundleMgr = Connect();
353 if (bundleMgr == nullptr) {
354 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
355 return false;
356 }
357
358 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
359 return bundleMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo);
360 }
361
GetPluginHapModuleInfo(const std::string & hostBundleName,const std::string & pluginBundleName,const std::string & pluginModuleName,const int32_t userId,HapModuleInfo & hapModuleInfo)362 ErrCode BundleMgrHelper::GetPluginHapModuleInfo(const std::string &hostBundleName, const std::string &pluginBundleName,
363 const std::string &pluginModuleName, const int32_t userId, HapModuleInfo &hapModuleInfo)
364 {
365 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "GetPluginHapModuleInfo");
366 auto bundleMgr = Connect();
367 if (bundleMgr == nullptr) {
368 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
369 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
370 }
371 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
372 return bundleMgr->GetPluginHapModuleInfo(hostBundleName, pluginBundleName, pluginModuleName, userId, hapModuleInfo);
373 }
374
GetAbilityLabel(const std::string & bundleName,const std::string & abilityName)375 std::string BundleMgrHelper::GetAbilityLabel(const std::string &bundleName, const std::string &abilityName)
376 {
377 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
378 auto bundleMgr = Connect();
379 if (bundleMgr == nullptr) {
380 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
381 return "";
382 }
383
384 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
385 return bundleMgr->GetAbilityLabel(bundleName, abilityName);
386 }
387
GetAppType(const std::string & bundleName)388 std::string BundleMgrHelper::GetAppType(const std::string &bundleName)
389 {
390 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
391 auto bundleMgr = Connect();
392 if (bundleMgr == nullptr) {
393 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
394 return "";
395 }
396
397 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
398 return bundleMgr->GetAppType(bundleName);
399 }
400
GetBaseSharedBundleInfos(const std::string & bundleName,std::vector<BaseSharedBundleInfo> & baseSharedBundleInfos,GetDependentBundleInfoFlag flag)401 ErrCode BundleMgrHelper::GetBaseSharedBundleInfos(
402 const std::string &bundleName, std::vector<BaseSharedBundleInfo> &baseSharedBundleInfos,
403 GetDependentBundleInfoFlag flag)
404 {
405 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
406 auto bundleMgr = Connect();
407 if (bundleMgr == nullptr) {
408 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
409 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
410 }
411
412 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
413 return bundleMgr->GetBaseSharedBundleInfos(bundleName, baseSharedBundleInfos, flag);
414 }
415
GetBundleInfoForSelf(int32_t flags,BundleInfo & bundleInfo)416 ErrCode BundleMgrHelper::GetBundleInfoForSelf(int32_t flags, BundleInfo &bundleInfo)
417 {
418 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
419 auto bundleMgr = Connect();
420 if (bundleMgr == nullptr) {
421 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
422 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
423 }
424
425 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
426 return bundleMgr->GetBundleInfoForSelf(flags, bundleInfo);
427 }
428
GetBundleInfoForSelfWithOutCache(int32_t flags,BundleInfo & bundleInfo)429 ErrCode BundleMgrHelper::GetBundleInfoForSelfWithOutCache(int32_t flags, BundleInfo &bundleInfo)
430 {
431 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
432 auto bundleMgr = Connect();
433 if (bundleMgr == nullptr) {
434 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
435 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
436 }
437
438 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
439 return bundleMgr->GetBundleInfoForSelfWithOutCache(flags, bundleInfo);
440 }
441
GetDependentBundleInfo(const std::string & sharedBundleName,BundleInfo & sharedBundleInfo,GetDependentBundleInfoFlag flag)442 ErrCode BundleMgrHelper::GetDependentBundleInfo(const std::string &sharedBundleName, BundleInfo &sharedBundleInfo,
443 GetDependentBundleInfoFlag flag)
444 {
445 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
446 auto bundleMgr = Connect();
447 if (bundleMgr == nullptr) {
448 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
449 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
450 }
451
452 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
453 return bundleMgr->GetDependentBundleInfo(sharedBundleName, sharedBundleInfo, flag);
454 }
455
GetGroupDir(const std::string & dataGroupId,std::string & dir)456 bool BundleMgrHelper::GetGroupDir(const std::string &dataGroupId, std::string &dir)
457 {
458 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
459 auto bundleMgr = Connect();
460 if (bundleMgr == nullptr) {
461 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
462 return false;
463 }
464
465 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
466 return bundleMgr->GetGroupDir(dataGroupId, dir);
467 }
468
GetOverlayManagerProxy()469 sptr<IOverlayManager> BundleMgrHelper::GetOverlayManagerProxy()
470 {
471 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
472 auto bundleMgr = Connect();
473 if (bundleMgr == nullptr) {
474 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
475 return nullptr;
476 }
477
478 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
479 return bundleMgr->GetOverlayManagerProxy();
480 }
481
QueryAbilityInfo(const Want & want,AbilityInfo & abilityInfo)482 bool BundleMgrHelper::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo)
483 {
484 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
485 auto bundleMgr = Connect();
486 if (bundleMgr == nullptr) {
487 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
488 return false;
489 }
490
491 AAFwk::Want newWant = want;
492 newWant.RemoveAllFd();
493 RecordCostTimeUtil("QueryAbilityInfoWithWant");
494 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
495 auto ret = bundleMgr->QueryAbilityInfo(newWant, abilityInfo);
496 SetAbilityProcessEmpty(abilityInfo);
497 return ret;
498 }
499
QueryAbilityInfo(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo)500 bool BundleMgrHelper::QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo)
501 {
502 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
503 auto bundleMgr = Connect();
504 if (bundleMgr == nullptr) {
505 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
506 return false;
507 }
508
509 AAFwk::Want newWant = want;
510 newWant.RemoveAllFd();
511 RecordCostTimeUtil("QueryAbilityInfoWithFlags");
512 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
513 auto ret = bundleMgr->QueryAbilityInfo(newWant, flags, userId, abilityInfo);
514 SetAbilityProcessEmpty(abilityInfo);
515 return ret;
516 }
517
GetBundleInfos(int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)518 bool BundleMgrHelper::GetBundleInfos(int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId)
519 {
520 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
521 auto bundleMgr = Connect();
522 if (bundleMgr == nullptr) {
523 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
524 return false;
525 }
526
527 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
528 return bundleMgr->GetBundleInfos(flags, bundleInfos, userId);
529 }
530
GetBundleInfos(const BundleFlag flag,std::vector<BundleInfo> & bundleInfos,int32_t userId)531 bool BundleMgrHelper::GetBundleInfos(const BundleFlag flag, std::vector<BundleInfo> &bundleInfos, int32_t userId)
532 {
533 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
534 auto bundleMgr = Connect();
535 if (bundleMgr == nullptr) {
536 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
537 return false;
538 }
539
540 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
541 return bundleMgr->GetBundleInfos(flag, bundleInfos, userId);
542 }
543
GetQuickFixManagerProxy()544 sptr<IQuickFixManager> BundleMgrHelper::GetQuickFixManagerProxy()
545 {
546 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
547 auto bundleMgr = Connect();
548 if (bundleMgr == nullptr) {
549 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
550 return nullptr;
551 }
552
553 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
554 return bundleMgr->GetQuickFixManagerProxy();
555 }
556
ProcessPreload(const Want & want)557 bool BundleMgrHelper::ProcessPreload(const Want &want)
558 {
559 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
560 auto bundleMgr = Connect();
561 if (bundleMgr == nullptr) {
562 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
563 return false;
564 }
565
566 AAFwk::Want newWant = want;
567 newWant.RemoveAllFd();
568 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
569 return bundleMgr->ProcessPreload(newWant);
570 }
571
GetAppControlProxy()572 sptr<IAppControlMgr> BundleMgrHelper::GetAppControlProxy()
573 {
574 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
575 auto bundleMgr = Connect();
576 if (bundleMgr == nullptr) {
577 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
578 return nullptr;
579 }
580
581 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
582 return bundleMgr->GetAppControlProxy();
583 }
584
QueryExtensionAbilityInfos(const Want & want,const int32_t & flag,const int32_t & userId,std::vector<ExtensionAbilityInfo> & extensionInfos)585 bool BundleMgrHelper::QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId,
586 std::vector<ExtensionAbilityInfo> &extensionInfos)
587 {
588 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
589 auto bundleMgr = Connect();
590 if (bundleMgr == nullptr) {
591 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
592 return false;
593 }
594
595 AAFwk::Want newWant = want;
596 newWant.RemoveAllFd();
597 RecordCostTimeUtil("QueryExtensionAbilityInfos");
598 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
599 return bundleMgr->QueryExtensionAbilityInfos(newWant, flag, userId, extensionInfos);
600 }
601
GetBundleInfoV9(const std::string & bundleName,int32_t flags,BundleInfo & bundleInfo,int32_t userId)602 ErrCode BundleMgrHelper::GetBundleInfoV9(
603 const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId)
604 {
605 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
606 auto bundleMgr = Connect();
607 if (bundleMgr == nullptr) {
608 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
609 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
610 }
611
612 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
613 return bundleMgr->GetBundleInfoV9(bundleName, flags, bundleInfo, userId);
614 }
615
GetApplicationInfo(const std::string & appName,const ApplicationFlag flag,const int32_t userId,ApplicationInfo & appInfo)616 bool BundleMgrHelper::GetApplicationInfo(
617 const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo)
618 {
619 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
620 auto bundleMgr = Connect();
621 if (bundleMgr == nullptr) {
622 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
623 return false;
624 }
625
626 RecordCostTimeUtil("GetApplicationInfoWithFlag");
627 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
628 return bundleMgr->GetApplicationInfo(appName, flag, userId, appInfo);
629 }
630
GetApplicationInfo(const std::string & appName,int32_t flags,int32_t userId,ApplicationInfo & appInfo)631 bool BundleMgrHelper::GetApplicationInfo(
632 const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo)
633 {
634 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
635 auto bundleMgr = Connect();
636 if (bundleMgr == nullptr) {
637 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
638 return false;
639 }
640
641 RecordCostTimeUtil("GetApplicationInfoWithFlags");
642 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
643 return bundleMgr->GetApplicationInfo(appName, flags, userId, appInfo);
644 }
645
GetApplicationInfoWithAppIndex(const std::string & appName,int32_t appIndex,int32_t userId,ApplicationInfo & appInfo)646 bool BundleMgrHelper::GetApplicationInfoWithAppIndex(
647 const std::string &appName, int32_t appIndex, int32_t userId, ApplicationInfo &appInfo)
648 {
649 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "appName: %{public}s, appIndex: %{public}d", appName.c_str(), appIndex);
650 if (appIndex < 0) {
651 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Invalid appIndex");
652 return false;
653 }
654 auto bundleMgr = Connect();
655 if (bundleMgr == nullptr) {
656 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
657 return false;
658 }
659
660 RecordCostTimeUtil("GetApplicationInfoWithAppIndex");
661 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
662 BundleInfo bundleInfo;
663 if (appIndex == 0) {
664 if (bundleMgr->GetApplicationInfo(appName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, userId, appInfo)) {
665 return true;
666 }
667 } else if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
668 if (bundleMgr->GetCloneBundleInfo(appName,
669 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
670 appIndex, bundleInfo, userId) == ERR_OK) {
671 appInfo = bundleInfo.applicationInfo;
672 return true;
673 }
674 } else {
675 if (bundleMgr->GetSandboxBundleInfo(appName, appIndex, userId, bundleInfo) == ERR_OK) {
676 appInfo = bundleInfo.applicationInfo;
677 return true;
678 }
679 }
680 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "GetApplicationInfo failed");
681 return false;
682 }
683
UnregisterBundleEventCallback(const sptr<IBundleEventCallback> & bundleEventCallback)684 bool BundleMgrHelper::UnregisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback)
685 {
686 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
687 if (bundleEventCallback == nullptr) {
688 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleEventCallback");
689 return false;
690 }
691
692 auto bundleMgr = Connect();
693 if (bundleMgr == nullptr) {
694 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
695 return false;
696 }
697
698 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
699 return bundleMgr->UnregisterBundleEventCallback(bundleEventCallback);
700 }
701
QueryExtensionAbilityInfoByUri(const std::string & uri,int32_t userId,ExtensionAbilityInfo & extensionAbilityInfo)702 bool BundleMgrHelper::QueryExtensionAbilityInfoByUri(
703 const std::string &uri, int32_t userId, ExtensionAbilityInfo &extensionAbilityInfo)
704 {
705 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
706 auto bundleMgr = Connect();
707 if (bundleMgr == nullptr) {
708 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
709 return false;
710 }
711
712 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
713 return bundleMgr->QueryExtensionAbilityInfoByUri(uri, userId, extensionAbilityInfo);
714 }
715
ImplicitQueryInfoByPriority(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo,ExtensionAbilityInfo & extensionInfo)716 bool BundleMgrHelper::ImplicitQueryInfoByPriority(
717 const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, ExtensionAbilityInfo &extensionInfo)
718 {
719 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
720 auto bundleMgr = Connect();
721 if (bundleMgr == nullptr) {
722 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
723 return false;
724 }
725 AAFwk::Want newWant = want;
726 newWant.RemoveAllFd();
727 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
728 auto ret = bundleMgr->ImplicitQueryInfoByPriority(newWant, flags, userId, abilityInfo, extensionInfo);
729 SetAbilityProcessEmpty(abilityInfo);
730 return ret;
731 }
732
QueryAbilityInfoByUri(const std::string & abilityUri,int32_t userId,AbilityInfo & abilityInfo)733 bool BundleMgrHelper::QueryAbilityInfoByUri(const std::string &abilityUri, int32_t userId, AbilityInfo &abilityInfo)
734 {
735 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
736 auto bundleMgr = Connect();
737 if (bundleMgr == nullptr) {
738 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
739 return false;
740 }
741
742 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
743 auto ret = bundleMgr->QueryAbilityInfoByUri(abilityUri, userId, abilityInfo);
744 SetAbilityProcessEmpty(abilityInfo);
745 return ret;
746 }
747
QueryAbilityInfo(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo,const sptr<IRemoteObject> & callBack)748 bool BundleMgrHelper::QueryAbilityInfo(
749 const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr<IRemoteObject> &callBack)
750 {
751 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
752 auto bundleMgr = Connect();
753 if (bundleMgr == nullptr) {
754 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
755 return false;
756 }
757
758 AAFwk::Want newWant = want;
759 newWant.RemoveAllFd();
760 RecordCostTimeUtil("QueryAbilityInfoWithCallback");
761 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
762 auto ret = bundleMgr->QueryAbilityInfo(newWant, flags, userId, abilityInfo, callBack);
763 SetAbilityProcessEmpty(abilityInfo);
764 return ret;
765 }
766
UpgradeAtomicService(const Want & want,int32_t userId)767 void BundleMgrHelper::UpgradeAtomicService(const Want &want, int32_t userId)
768 {
769 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
770 auto bundleMgr = Connect();
771 if (bundleMgr == nullptr) {
772 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
773 return;
774 }
775
776 AAFwk::Want newWant = want;
777 newWant.RemoveAllFd();
778 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
779 bundleMgr->UpgradeAtomicService(newWant, userId);
780 }
781
ImplicitQueryInfos(const Want & want,int32_t flags,int32_t userId,bool withDefault,std::vector<AbilityInfo> & abilityInfos,std::vector<ExtensionAbilityInfo> & extensionInfos,bool & findDefaultApp)782 bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault,
783 std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos, bool &findDefaultApp)
784 {
785 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
786 auto bundleMgr = Connect();
787 if (bundleMgr == nullptr) {
788 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
789 return false;
790 }
791
792 AAFwk::Want newWant = want;
793 newWant.RemoveAllFd();
794 RecordCostTimeUtil("ImplicitQueryInfos");
795 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
796 bool ret = bundleMgr->ImplicitQueryInfos(newWant, flags, userId, withDefault, abilityInfos,
797 extensionInfos, findDefaultApp);
798 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "findDefaultApp is %{public}d.", findDefaultApp);
799 for (auto abilityInfo: abilityInfos) {
800 SetAbilityProcessEmpty(abilityInfo);
801 }
802 return ret;
803 }
804
CleanBundleDataFiles(const std::string & bundleName,int32_t userId,int32_t appCloneIndex,int32_t callerUid)805 bool BundleMgrHelper::CleanBundleDataFiles(
806 const std::string &bundleName, int32_t userId, int32_t appCloneIndex, int32_t callerUid)
807 {
808 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
809 auto bundleMgr = Connect();
810 if (bundleMgr == nullptr) {
811 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
812 return false;
813 }
814
815 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
816 return bundleMgr->CleanBundleDataFiles(bundleName, userId, appCloneIndex, callerUid);
817 }
818
QueryDataGroupInfos(const std::string & bundleName,int32_t userId,std::vector<DataGroupInfo> & infos)819 bool BundleMgrHelper::QueryDataGroupInfos(
820 const std::string &bundleName, int32_t userId, std::vector<DataGroupInfo> &infos)
821 {
822 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
823 auto bundleMgr = Connect();
824 if (bundleMgr == nullptr) {
825 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
826 return false;
827 }
828
829 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
830 return bundleMgr->QueryDataGroupInfos(bundleName, userId, infos);
831 }
832
RegisterBundleEventCallback(const sptr<IBundleEventCallback> & bundleEventCallback)833 bool BundleMgrHelper::RegisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback)
834 {
835 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
836 if (bundleEventCallback == nullptr) {
837 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleEventCallback");
838 return false;
839 }
840
841 auto bundleMgr = Connect();
842 if (bundleMgr == nullptr) {
843 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
844 return false;
845 }
846
847 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
848 return bundleMgr->RegisterBundleEventCallback(bundleEventCallback);
849 }
850
GetHapModuleInfo(const AbilityInfo & abilityInfo,int32_t userId,HapModuleInfo & hapModuleInfo)851 bool BundleMgrHelper::GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo)
852 {
853 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
854 auto bundleMgr = Connect();
855 if (bundleMgr == nullptr) {
856 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
857 return false;
858 }
859
860 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
861 return bundleMgr->GetHapModuleInfo(abilityInfo, userId, hapModuleInfo);
862 }
863
QueryAppGalleryBundleName(std::string & bundleName)864 bool BundleMgrHelper::QueryAppGalleryBundleName(std::string &bundleName)
865 {
866 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
867 auto bundleMgr = Connect();
868 if (bundleMgr == nullptr) {
869 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
870 return false;
871 }
872
873 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
874 return bundleMgr->QueryAppGalleryBundleName(bundleName);
875 }
876
GetUidByBundleName(const std::string & bundleName,int32_t userId,int32_t appCloneIndex)877 ErrCode BundleMgrHelper::GetUidByBundleName(const std::string &bundleName, int32_t userId, int32_t appCloneIndex)
878 {
879 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
880 auto bundleMgr = Connect();
881 if (bundleMgr == nullptr) {
882 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
883 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
884 }
885
886 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
887 return bundleMgr->GetUidByBundleName(bundleName, userId, appCloneIndex);
888 }
889
QueryExtensionAbilityInfosOnlyWithTypeName(const std::string & extensionTypeName,const uint32_t flag,const int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)890 ErrCode BundleMgrHelper::QueryExtensionAbilityInfosOnlyWithTypeName(const std::string &extensionTypeName,
891 const uint32_t flag, const int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
892 {
893 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
894 auto bundleMgr = Connect();
895 if (bundleMgr == nullptr) {
896 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
897 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
898 }
899
900 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
901 return bundleMgr->QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, flag, userId, extensionInfos);
902 }
903
GetDefaultAppProxy()904 sptr<IDefaultApp> BundleMgrHelper::GetDefaultAppProxy()
905 {
906 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
907 auto bundleMgr = Connect();
908 if (bundleMgr == nullptr) {
909 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
910 return nullptr;
911 }
912
913 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
914 return bundleMgr->GetDefaultAppProxy();
915 }
916
GetJsonProfile(ProfileType profileType,const std::string & bundleName,const std::string & moduleName,std::string & profile,int32_t userId)917 ErrCode BundleMgrHelper::GetJsonProfile(ProfileType profileType, const std::string &bundleName,
918 const std::string &moduleName, std::string &profile, int32_t userId)
919 {
920 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
921 auto bundleMgr = Connect();
922 if (bundleMgr == nullptr) {
923 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
924 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
925 }
926
927 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
928 return bundleMgr->GetJsonProfile(profileType, bundleName, moduleName, profile, userId);
929 }
930
GetLaunchWantForBundle(const std::string & bundleName,Want & want,int32_t userId)931 ErrCode BundleMgrHelper::GetLaunchWantForBundle(const std::string &bundleName, Want &want, int32_t userId)
932 {
933 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
934 auto bundleMgr = Connect();
935 if (bundleMgr == nullptr) {
936 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
937 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
938 }
939
940 want.RemoveAllFd();
941 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
942 return bundleMgr->GetLaunchWantForBundle(bundleName, want, userId);
943 }
944
QueryCloneAbilityInfo(const ElementName & element,int32_t flags,int32_t appCloneIndex,AbilityInfo & abilityInfo,int32_t userId)945 ErrCode BundleMgrHelper::QueryCloneAbilityInfo(const ElementName &element, int32_t flags, int32_t appCloneIndex,
946 AbilityInfo &abilityInfo, int32_t userId)
947 {
948 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
949 auto bundleMgr = Connect();
950 if (bundleMgr == nullptr) {
951 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
952 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
953 }
954
955 RecordCostTimeUtil("QueryCloneAbilityInfo");
956 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
957 auto ret = bundleMgr->QueryCloneAbilityInfo(element, flags, appCloneIndex, abilityInfo, userId);
958 SetAbilityProcessEmpty(abilityInfo);
959 return ret;
960 }
961
GetCloneBundleInfo(const std::string & bundleName,int32_t flags,int32_t appCloneIndex,BundleInfo & bundleInfo,int32_t userId)962 ErrCode BundleMgrHelper::GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex,
963 BundleInfo &bundleInfo, int32_t userId)
964 {
965 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
966 auto bundleMgr = Connect();
967 if (bundleMgr == nullptr) {
968 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
969 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
970 }
971
972 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
973 return bundleMgr->GetCloneBundleInfo(bundleName, flags, appCloneIndex, bundleInfo, userId);
974 }
975
QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName & element,int32_t flags,int32_t appCloneIndex,ExtensionAbilityInfo & extensionInfo,int32_t userId)976 ErrCode BundleMgrHelper::QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName &element, int32_t flags,
977 int32_t appCloneIndex, ExtensionAbilityInfo &extensionInfo, int32_t userId)
978 {
979 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
980 auto bundleMgr = Connect();
981 if (bundleMgr == nullptr) {
982 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
983 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
984 }
985
986 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
987 return bundleMgr->QueryCloneExtensionAbilityInfoWithAppIndex(element, flags, appCloneIndex, extensionInfo, userId);
988 }
989
GetCloneAppIndexes(const std::string & bundleName,std::vector<int32_t> & appIndexes,int32_t userId)990 ErrCode BundleMgrHelper::GetCloneAppIndexes(const std::string &bundleName, std::vector<int32_t> &appIndexes,
991 int32_t userId)
992 {
993 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called");
994 auto bundleMgr = Connect();
995 if (bundleMgr == nullptr) {
996 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
997 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
998 }
999
1000 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1001 return bundleMgr->GetCloneAppIndexes(bundleName, appIndexes, userId);
1002 }
1003
GetSignatureInfoByBundleName(const std::string & bundleName,SignatureInfo & signatureInfo)1004 ErrCode BundleMgrHelper::GetSignatureInfoByBundleName(const std::string &bundleName, SignatureInfo &signatureInfo)
1005 {
1006 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called");
1007 auto bundleMgr = Connect();
1008 if (bundleMgr == nullptr) {
1009 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1010 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1011 }
1012
1013 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1014 return bundleMgr->GetSignatureInfoByBundleName(bundleName, signatureInfo);
1015 }
1016
GetStringById(const std::string & bundleName,const std::string & moduleName,uint32_t resId,int32_t userId)1017 std::string BundleMgrHelper::GetStringById(
1018 const std::string &bundleName, const std::string &moduleName, uint32_t resId, int32_t userId)
1019 {
1020 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
1021 auto bundleMgr = Connect();
1022 if (bundleMgr == nullptr) {
1023 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect");
1024 return "";
1025 }
1026
1027 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1028 return bundleMgr->GetStringById(bundleName, moduleName, resId, userId);
1029 }
1030
GetDataDir(const std::string & bundleName,const int32_t appIndex)1031 std::string BundleMgrHelper::GetDataDir(const std::string &bundleName, const int32_t appIndex)
1032 {
1033 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
1034 auto bundleMgr = Connect();
1035 if (bundleMgr == nullptr) {
1036 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect");
1037 return "";
1038 }
1039
1040 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1041 std::string dataDir;
1042 bundleMgr->GetDirByBundleNameAndAppIndex(bundleName, appIndex, dataDir);
1043 return dataDir;
1044 }
1045
GetPluginInfosForSelf(std::vector<PluginBundleInfo> & pluginBundleInfos)1046 ErrCode BundleMgrHelper::GetPluginInfosForSelf(std::vector<PluginBundleInfo> &pluginBundleInfos)
1047 {
1048 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
1049 auto bundleMgr = Connect();
1050 if (bundleMgr == nullptr) {
1051 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1052 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1053 }
1054 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1055 return bundleMgr->GetPluginInfosForSelf(pluginBundleInfos);
1056 }
1057
GetPluginAbilityInfo(const std::string & hostBundleName,const std::string & pluginBundleName,const std::string & pluginModuleName,const std::string & pluginAbilityName,int32_t userId,AbilityInfo & pluginAbilityInfo)1058 ErrCode BundleMgrHelper::GetPluginAbilityInfo(const std::string &hostBundleName, const std::string &pluginBundleName,
1059 const std::string &pluginModuleName, const std::string &pluginAbilityName, int32_t userId,
1060 AbilityInfo &pluginAbilityInfo)
1061 {
1062 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "GetPluginAbilityInfo");
1063 auto bundleMgr = Connect();
1064 if (bundleMgr == nullptr) {
1065 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1066 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1067 }
1068 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1069 return bundleMgr->GetPluginAbilityInfo(hostBundleName, pluginBundleName, pluginModuleName, pluginAbilityName,
1070 userId, pluginAbilityInfo);
1071 }
1072
RegisterPluginEventCallback(sptr<IBundleEventCallback> pluginEventCallback)1073 ErrCode BundleMgrHelper::RegisterPluginEventCallback(sptr<IBundleEventCallback> pluginEventCallback)
1074 {
1075 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "RegisterPluginEventCallback");
1076 auto bundleMgr = Connect();
1077 if (bundleMgr == nullptr) {
1078 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1079 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1080 }
1081 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1082 return bundleMgr->RegisterPluginEventCallback(pluginEventCallback);
1083 }
1084
UnregisterPluginEventCallback(sptr<IBundleEventCallback> pluginEventCallback)1085 ErrCode BundleMgrHelper::UnregisterPluginEventCallback(sptr<IBundleEventCallback> pluginEventCallback)
1086 {
1087 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "UnregisterPluginEventCallback");
1088 auto bundleMgr = Connect();
1089 if (bundleMgr == nullptr) {
1090 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1091 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1092 }
1093 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1094 return bundleMgr->UnregisterPluginEventCallback(pluginEventCallback);
1095 }
1096
GetCloneBundleInfoExt(const std::string & bundleName,uint32_t flags,int32_t appIndex,int32_t userId,BundleInfo & bundleInfo)1097 ErrCode BundleMgrHelper::GetCloneBundleInfoExt(const std::string &bundleName, uint32_t flags, int32_t appIndex,
1098 int32_t userId, BundleInfo &bundleInfo)
1099 {
1100 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "GetCloneBundleInfoExt");
1101 auto bundleMgr = Connect();
1102 if (bundleMgr == nullptr) {
1103 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1104 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1105 }
1106 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1107 return bundleMgr->GetCloneBundleInfoExt(bundleName, flags, appIndex, userId, bundleInfo);
1108 }
1109
GetLauncherAbilityInfoSync(const std::string & bundleName,int32_t userId,std::vector<AbilityInfo> & abilityInfo)1110 ErrCode BundleMgrHelper::GetLauncherAbilityInfoSync(const std::string &bundleName, int32_t userId,
1111 std::vector<AbilityInfo> &abilityInfo)
1112 {
1113 TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "GetLauncherAbilityInfoSync");
1114 auto bundleMgr = Connect();
1115 if (bundleMgr == nullptr) {
1116 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1117 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1118 }
1119 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1120 return bundleMgr->GetLauncherAbilityInfoSync(bundleName, userId, abilityInfo);
1121 }
1122
GetPluginInfoForTarget(const std::string & hostBundleName,const std::string & pluginBundleName,int32_t userId,PluginBundleInfo & pluginBundleInfo)1123 ErrCode BundleMgrHelper::GetPluginInfoForTarget(const std::string &hostBundleName,
1124 const std::string &pluginBundleName, int32_t userId, PluginBundleInfo &pluginBundleInfo)
1125 {
1126 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
1127 auto bundleMgr = Connect();
1128 if (bundleMgr == nullptr) {
1129 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1130 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1131 }
1132 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1133 return bundleMgr->GetPluginInfo(hostBundleName, pluginBundleName, userId, pluginBundleInfo);
1134 }
1135
GetTestRunnerTypeAndPath(const std::string & bundleName,const std::string & moduleName,ModuleTestRunner & testRunner)1136 ErrCode BundleMgrHelper::GetTestRunnerTypeAndPath(const std::string &bundleName, const std::string &moduleName,
1137 ModuleTestRunner &testRunner)
1138 {
1139 TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
1140 auto bundleMgr = Connect();
1141 if (bundleMgr == nullptr) {
1142 TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr");
1143 return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
1144 }
1145 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1146 return bundleMgr->GetTestRunner(bundleName, moduleName, testRunner);
1147 }
1148 } // namespace AppExecFwk
1149 } // namespace OHOS