• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "adapter/dnetwork_adapter.h"
17 #include "bundle/bundle_manager_internal.h"
18 #include "bundle/bundle_manager_callback_stub.h"
19 #include "distributed_sched_adapter.h"
20 #include "distributed_sched_utils.h"
21 #include "dtbschedmgr_log.h"
22 #include "mission/dsched_sync_e2e.h"
23 #include "ipc_skeleton.h"
24 #include "iservice_registry.h"
25 #include "os_account_manager.h"
26 #include "system_ability_definition.h"
27 
28 namespace OHOS {
29 namespace DistributedSchedule {
30 using namespace AccountSA;
31 namespace {
32 const std::string TAG = "BundleManagerInternal";
33 }
34 IMPLEMENT_SINGLE_INSTANCE(BundleManagerInternal);
GetCallerAppIdFromBms(int32_t callingUid,std::string & appId)35 bool BundleManagerInternal::GetCallerAppIdFromBms(int32_t callingUid, std::string& appId)
36 {
37     std::vector<std::string> bundleNameList;
38     if (!GetBundleNameListFromBms(callingUid, bundleNameList)) {
39         HILOGE("GetBundleNameListFromBms failed");
40         return false;
41     }
42     if (bundleNameList.empty()) {
43         HILOGE("bundleNameList empty");
44         return false;
45     }
46     // getting an arbitrary bundlename for they sharing a same appId, here we get the first one
47     return GetCallerAppIdFromBms(bundleNameList.front(), appId);
48 }
49 
GetCallerAppIdFromBms(const std::string & bundleName,std::string & appId)50 bool BundleManagerInternal::GetCallerAppIdFromBms(const std::string& bundleName, std::string& appId)
51 {
52     auto bundleMgr = GetBundleManager();
53     if (bundleMgr == nullptr) {
54         HILOGE("failed to get bms");
55         return false;
56     }
57     int32_t activeAccountId = 0;
58     ErrCode err = QueryOsAccount(activeAccountId);
59     if (err != ERR_OK) {
60         return false;
61     }
62     appId = bundleMgr->GetAppIdByBundleName(bundleName, activeAccountId);
63     HILOGD("appId:%s", GetAnonymStr(appId).c_str());
64     return true;
65 }
66 
GetSpecifyBundleNameFromBms(int32_t callingUid,std::string & bundleName)67 bool BundleManagerInternal::GetSpecifyBundleNameFromBms(int32_t callingUid, std::string& bundleName)
68 {
69     auto bundleMgr = GetBundleManager();
70     if (bundleMgr == nullptr) {
71         HILOGE("failed to get bms");
72         return false;
73     }
74     bool result = bundleMgr->GetBundleNameForUid(callingUid, bundleName);
75     if (!result) {
76         HILOGE("Get specify bundle name for uid failed, result: %{public}d", result);
77         return false;
78     }
79     return result;
80 }
81 
GetBundleNameListFromBms(int32_t callingUid,std::vector<std::string> & bundleNameList)82 bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid, std::vector<std::string>& bundleNameList)
83 {
84     auto bundleMgr = GetBundleManager();
85     if (bundleMgr == nullptr) {
86         HILOGE("failed to get bms");
87         return false;
88     }
89     bool result = bundleMgr->GetBundlesForUid(callingUid, bundleNameList);
90     if (!result) {
91         HILOGE("Get bundle name list for userId which the uid belongs failed, result: %{public}d", result);
92         return false;
93     }
94     return result;
95 }
96 
GetBundleNameListFromBms(int32_t callingUid,std::vector<std::u16string> & u16BundleNameList)97 bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid,
98     std::vector<std::u16string>& u16BundleNameList)
99 {
100     std::vector<std::string> bundleNameList;
101     if (!GetBundleNameListFromBms(callingUid, bundleNameList)) {
102         HILOGE("Get bundle name list for userId which the uid belongs failed.");
103         return false;
104     }
105     for (const std::string& bundleName : bundleNameList) {
106         u16BundleNameList.emplace_back(Str8ToStr16(bundleName));
107     }
108     return true;
109 }
110 
QueryAbilityInfo(const AAFwk::Want & want,AppExecFwk::AbilityInfo & abilityInfo)111 bool BundleManagerInternal::QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo)
112 {
113     int32_t activeAccountId = 0;
114     ErrCode err = QueryOsAccount(activeAccountId);
115     if (err != ERR_OK) {
116         return false;
117     }
118     auto bundleMgr = GetBundleManager();
119     if (bundleMgr == nullptr) {
120         HILOGE("failed to get bms");
121         return false;
122     }
123     bool result = bundleMgr->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT
124         | AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, activeAccountId, abilityInfo);
125     if (!result) {
126         HILOGW("QueryAbilityInfo failed");
127         return false;
128     }
129     return true;
130 }
131 
QueryExtensionAbilityInfo(const AAFwk::Want & want,AppExecFwk::ExtensionAbilityInfo & extensionInfo)132 bool BundleManagerInternal::QueryExtensionAbilityInfo(const AAFwk::Want& want,
133     AppExecFwk::ExtensionAbilityInfo& extensionInfo)
134 {
135     int32_t activeAccountId = 0;
136     ErrCode err = QueryOsAccount(activeAccountId);
137     if (err != ERR_OK) {
138         return false;
139     }
140     auto bundleMgr = GetBundleManager();
141     if (bundleMgr == nullptr) {
142         HILOGE("failed to get bms");
143         return false;
144     }
145     std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
146     bundleMgr->QueryExtensionAbilityInfos(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT
147         | AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, activeAccountId, extensionInfos);
148     if (extensionInfos.empty()) {
149         HILOGE("QueryExtensionAbilityInfo failed.");
150         return false;
151     }
152     extensionInfo = extensionInfos.front();
153     if (extensionInfo.bundleName.empty() || extensionInfo.name.empty()) {
154         HILOGE("ExtensionAbilityInfo is empty.");
155         return false;
156     }
157     HILOGD("ExtensionAbilityInfo found, name=%{public}s.", extensionInfo.name.c_str());
158     return true;
159 }
160 
InitAbilityInfoFromExtension(const AppExecFwk::ExtensionAbilityInfo & extensionAbilityInfo,AppExecFwk::AbilityInfo & abilityInfo)161 void BundleManagerInternal::InitAbilityInfoFromExtension(const AppExecFwk::ExtensionAbilityInfo &extensionAbilityInfo,
162     AppExecFwk::AbilityInfo &abilityInfo)
163 {
164     abilityInfo.bundleName = extensionAbilityInfo.bundleName;
165     abilityInfo.name = extensionAbilityInfo.name;
166     abilityInfo.permissions = extensionAbilityInfo.permissions;
167     abilityInfo.visible = extensionAbilityInfo.visible;
168 }
169 
IsSameAppId(const std::string & callerAppId,const std::string & targetBundleName)170 bool BundleManagerInternal::IsSameAppId(const std::string& callerAppId, const std::string& targetBundleName)
171 {
172     if (targetBundleName.empty() || callerAppId.empty()) {
173         HILOGE("targetBundleName:%{public}s or callerAppId:%s is empty",
174             targetBundleName.c_str(), GetAnonymStr(callerAppId).c_str());
175         return false;
176     }
177     HILOGD("callerAppId:%s", GetAnonymStr(callerAppId).c_str());
178     std::string calleeAppId;
179     if (!GetCallerAppIdFromBms(targetBundleName, calleeAppId)) {
180         HILOGE("GetCallerAppIdFromBms failed");
181         return false;
182     }
183     HILOGD("calleeAppId:%s", GetAnonymStr(calleeAppId).c_str());
184     return callerAppId == calleeAppId;
185 }
186 
IsSameDeveloperId(const std::string & bundleNameInCurrentSide,const std::string & developerId4OtherSide)187 bool BundleManagerInternal::IsSameDeveloperId(const std::string &bundleNameInCurrentSide,
188     const std::string &developerId4OtherSide)
189 {
190     if (bundleNameInCurrentSide.empty() || developerId4OtherSide.empty()) {
191         HILOGE("bundleNameInCurrentSide: %{public}s or developerId4OtherSide: %{public}s is empty",
192             bundleNameInCurrentSide.c_str(), developerId4OtherSide.c_str());
193         return false;
194     }
195 
196     auto bundleMgr = GetBundleManager();
197     if (bundleMgr == nullptr) {
198         HILOGE("get bundle manager failed");
199         return false;
200     }
201     AppExecFwk::AppProvisionInfo targetAppProvisionInfo;
202     std::vector<int32_t> ids;
203     ErrCode ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
204     if (ret != ERR_OK || ids.empty()) {
205         HILOGE("Get userId from active Os AccountIds fail, ret : %{public}d", ret);
206         return false;
207     }
208     bundleMgr->GetAppProvisionInfo(bundleNameInCurrentSide, ids[0], targetAppProvisionInfo);
209     return developerId4OtherSide == targetAppProvisionInfo.developerId;
210 }
211 
GetLocalBundleInfo(const std::string & bundleName,AppExecFwk::BundleInfo & localBundleInfo)212 int32_t BundleManagerInternal::GetLocalBundleInfo(const std::string& bundleName,
213     AppExecFwk::BundleInfo &localBundleInfo)
214 {
215     auto bms = GetBundleManager();
216     if (bms == nullptr) {
217         HILOGE("get bundle manager failed");
218         return INVALID_PARAMETERS_ERR;
219     }
220 
221     int32_t activeAccountId = 0;
222     ErrCode err = QueryOsAccount(activeAccountId);
223     if (err != ERR_OK) {
224         return err;
225     }
226     if (!bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES,
227         localBundleInfo, activeAccountId)) {
228         HILOGE("get local bundle info failed");
229         return INVALID_PARAMETERS_ERR;
230     }
231     return ERR_OK;
232 }
233 
GetLocalBundleInfoV9(const std::string & bundleName,AppExecFwk::BundleInfo & bundleInfo)234 int32_t BundleManagerInternal::GetLocalBundleInfoV9(const std::string& bundleName,
235     AppExecFwk::BundleInfo &bundleInfo)
236 {
237     auto bms = GetBundleManager();
238     if (bms == nullptr) {
239         HILOGE("get bundle manager failed");
240         return INVALID_PARAMETERS_ERR;
241     }
242 
243     int32_t activeAccountId = 0;
244     ErrCode ret = QueryOsAccount(activeAccountId);
245     if (ret != ERR_OK) {
246         return ret;
247     }
248     ret = bms->GetBundleInfoV9(bundleName,
249         static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
250         bundleInfo, activeAccountId);
251     if (ret != ERR_OK) {
252         HILOGE("get local bundle info failed, ret: %{public}d", ret);
253     }
254     return ret;
255 }
256 
GetLocalAbilityInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,AppExecFwk::AbilityInfo & abilityInfo)257 int32_t BundleManagerInternal::GetLocalAbilityInfo(const std::string& bundleName,
258     const std::string& moduleName, const std::string& abilityName, AppExecFwk::AbilityInfo &abilityInfo)
259 {
260     AppExecFwk::BundleInfo bundleInfo;
261     ErrCode ret = GetLocalBundleInfo(bundleName, bundleInfo);
262     if (ret != ERR_OK) {
263         HILOGE("get local bundle info failed");
264         return ret;
265     }
266     for (auto ability : bundleInfo.abilityInfos) {
267         if (ability.moduleName == moduleName && ability.name == abilityName) {
268             abilityInfo = ability;
269             break;
270         }
271     }
272     return ERR_OK;
273 }
274 
GetContinueBundle4Src(const std::string & srcBundleName,std::vector<std::string> & bundleNameList)275 bool BundleManagerInternal::GetContinueBundle4Src(const std::string &srcBundleName,
276     std::vector<std::string> &bundleNameList)
277 {
278     auto bundleMgr = GetBundleManager();
279     if (bundleMgr == nullptr) {
280         HILOGE("get bundle manager failed");
281         return false;
282     }
283 
284     int32_t activeAccountId = 0;
285     ErrCode ret = QueryOsAccount(activeAccountId);
286     if (ret != ERR_OK) {
287         HILOGE("get os account id failed");
288         return false;
289     }
290     ret = bundleMgr->GetContinueBundleNames(srcBundleName, bundleNameList, activeAccountId);
291     if (ret != ERR_OK || bundleNameList.empty()) {
292         HILOGW("No APP with specified bundle name(%{public}s) configured in continue Bundle; ret: %{public}d",
293             srcBundleName.c_str(), ret);
294         return false;
295     }
296     return true;
297 }
298 
GetAppProvisionInfo4CurrentUser(const std::string & bundleName,AppExecFwk::AppProvisionInfo & appProvisionInfo)299 bool BundleManagerInternal::GetAppProvisionInfo4CurrentUser(const std::string &bundleName,
300     AppExecFwk::AppProvisionInfo &appProvisionInfo)
301 {
302     sptr<AppExecFwk::IBundleMgr> bundleMgr = GetBundleManager();
303     if (bundleMgr == nullptr) {
304         HILOGE("get bundle manager failed");
305         return false;
306     }
307     std::vector<int32_t> ids;
308     ErrCode ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
309     if (ret != ERR_OK || ids.empty()) {
310         HILOGE("Get userId from active Os AccountIds fail, ret : %{public}d", ret);
311         return false;
312     }
313     ErrCode result = bundleMgr->GetAppProvisionInfo(bundleName, ids[0], appProvisionInfo);
314     HILOGI("find local bundle name for diff bundle continue. local developer id: %{public}s; ",
315         GetAnonymStr(appProvisionInfo.developerId).c_str());
316     return result == ERR_OK;
317 }
318 
CheckRemoteBundleInfoForContinuation(const std::string & dstDeviceId,const std::string & bundleName,AppExecFwk::DistributedBundleInfo & remoteBundleInfo)319 int32_t BundleManagerInternal::CheckRemoteBundleInfoForContinuation(const std::string& dstDeviceId,
320     const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo)
321 {
322     if (bundleName.empty()) {
323         HILOGE("bundle name empty");
324         return INVALID_PARAMETERS_ERR;
325     }
326     HILOGI("bundleName: %{public}s", bundleName.c_str());
327 
328     auto bms = GetBundleManager();
329     if (bms == nullptr) {
330         HILOGE("get bundle manager failed");
331         return INVALID_PARAMETERS_ERR;
332     }
333 
334     bool isInstalled = bms->GetDistributedBundleInfo(dstDeviceId, bundleName, remoteBundleInfo);
335     if (isInstalled) {
336         return ERR_OK;
337     }
338 
339     AppExecFwk::BundleInfo localBundleInfo;
340     if (GetLocalBundleInfo(bundleName, localBundleInfo) != ERR_OK) {
341         HILOGE("get local bundle info failed");
342         return INVALID_PARAMETERS_ERR;
343     }
344     if (localBundleInfo.entryInstallationFree) {
345         return CONTINUE_REMOTE_UNINSTALLED_SUPPORT_FREEINSTALL;
346     }
347     return CONTINUE_REMOTE_UNINSTALLED_UNSUPPORT_FREEINSTALL;
348 }
349 
CheckIfRemoteCanInstall(const AAFwk::Want & want,int32_t missionId)350 bool BundleManagerInternal::CheckIfRemoteCanInstall(const AAFwk::Want& want, int32_t missionId)
351 {
352     std::string bundleName = want.GetElement().GetBundleName();
353     std::string moduleName = want.GetElement().GetModuleName();
354     std::string abilityName = want.GetElement().GetAbilityName();
355     std::string deviceId = want.GetElement().GetDeviceID();
356     std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId);
357     HILOGD("bundleName = %{public}s, moduleName = %{public}s, abilityName = %{public}s, udid = %{public}s",
358         bundleName.c_str(), moduleName.c_str(), abilityName.c_str(), GetAnonymStr(udid).c_str());
359 
360     if (bundleName.empty() || moduleName.empty() || abilityName.empty() || udid.empty()) {
361         HILOGE("udid or bundle or module or ability name is empty");
362         return false;
363     }
364     auto bms = GetBundleManager();
365     if (bms == nullptr) {
366         HILOGE("get bundle manager failed");
367         return false;
368     }
369 
370     AAFwk::Want newWant;
371     newWant.SetElementName(udid, bundleName, abilityName, moduleName);
372     int32_t activeAccountId = 0;
373     ErrCode err = QueryOsAccount(activeAccountId);
374     if (err != ERR_OK) {
375         return false;
376     }
377     bool ret = bms->CheckAbilityEnableInstall(newWant, missionId, activeAccountId, new DmsBundleManagerCallbackStub());
378     if (ret != true) {
379         HILOGE("CheckAbilityEnableInstall from bms failed");
380     }
381     return ret;
382 }
383 
GetBundleManager()384 sptr<AppExecFwk::IBundleMgr> BundleManagerInternal::GetBundleManager()
385 {
386     sptr<ISystemAbilityManager> samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
387     if (samgrProxy == nullptr) {
388         return nullptr;
389     }
390     sptr<IRemoteObject> bmsProxy = samgrProxy->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
391     if (bmsProxy == nullptr) {
392         HILOGE("failed to get bms from samgr");
393         return nullptr;
394     }
395     return iface_cast<AppExecFwk::IBundleMgr>(bmsProxy);
396 }
397 
GetDistributedBundleManager()398 sptr<AppExecFwk::IDistributedBms> BundleManagerInternal::GetDistributedBundleManager()
399 {
400     sptr<ISystemAbilityManager> samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
401     if (samgrProxy == nullptr) {
402         HILOGE("failed to get samgrProxy from dbms");
403         return nullptr;
404     }
405     sptr<IRemoteObject> dbmsProxy = samgrProxy->GetSystemAbility(DISTRIBUTED_BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
406     if (dbmsProxy == nullptr) {
407         HILOGE("failed to get dbmsProxy from dbms");
408         return nullptr;
409     }
410     return iface_cast<AppExecFwk::IDistributedBms>(dbmsProxy);
411 }
412 
GetUidFromBms(const std::string & bundleName)413 int32_t BundleManagerInternal::GetUidFromBms(const std::string& bundleName)
414 {
415     auto bundleMgr = GetBundleManager();
416     if (bundleMgr == nullptr) {
417         HILOGE("failed to get bms");
418         return -1;
419     }
420     int32_t activeAccountId = 0;
421     ErrCode err = QueryOsAccount(activeAccountId);
422     if (err != ERR_OK) {
423         return err;
424     }
425     return bundleMgr->GetUidByBundleName(bundleName, activeAccountId);
426 }
427 
GetBundleNameId(const std::string & bundleName,uint16_t & bundleNameId)428 int32_t BundleManagerInternal::GetBundleNameId(const std::string& bundleName, uint16_t& bundleNameId)
429 {
430     HILOGD("called.");
431     bool ret = DmsBmStorage::GetInstance()->GetBundleNameId(bundleName, bundleNameId);
432     HILOGI("bundleNameId: %{public}d end.", bundleNameId);
433     if (!ret) {
434         HILOGE("can not get bundleNameId by bundleName");
435         return CAN_NOT_FOUND_ABILITY_ERR;
436     }
437     HILOGD("end.");
438     return ERR_OK;
439 }
440 
GetContinueType(const std::string & networkId,std::string & bundleName,uint8_t continueTypeId)441 std::string BundleManagerInternal::GetContinueType(const std::string &networkId,
442     std::string &bundleName, uint8_t continueTypeId)
443 {
444     HILOGD("called.");
445     std::string continueType = DmsBmStorage::GetInstance()->GetContinueType(networkId, bundleName, continueTypeId);
446     HILOGI("continueType: %{public}s end.", continueType.c_str());
447     if (continueType == "") {
448         HILOGE("can not get continueType!");
449     }
450     HILOGD("end.");
451     return continueType;
452 }
453 
GetContinueTypeId(const std::string & bundleName,const std::string & abilityName,uint8_t & continueTypeId)454 int32_t BundleManagerInternal::GetContinueTypeId(const std::string &bundleName,
455     const std::string &abilityName, uint8_t &continueTypeId)
456 {
457     HILOGD("called.");
458     bool ret = DmsBmStorage::GetInstance()->GetContinueTypeId(bundleName, abilityName, continueTypeId);
459     HILOGI("ContinueTypeId: %{public}d ", continueTypeId);
460     if (!ret) {
461         HILOGE("can not get ContinueTypeId!");
462         return CAN_NOT_FOUND_ABILITY_ERR;
463     }
464     HILOGD("end.");
465     return ERR_OK;
466 }
467 
GetAbilityName(const std::string & networkId,std::string & bundleName,std::string & continueType)468 std::string BundleManagerInternal::GetAbilityName(const std::string &networkId,
469     std::string &bundleName, std::string &continueType)
470 {
471     HILOGI("called. continueType: %{public}s ", continueType.c_str());
472     std::string abilityName = DmsBmStorage::GetInstance()->GetAbilityName(networkId, bundleName, continueType);
473     if (abilityName == "") {
474         HILOGE("can not get abilityName!");
475     }
476     HILOGD("end.");
477     return abilityName;
478 }
479 
GetBundleNameById(const std::string & networkId,const uint16_t & bundleNameId,std::string & bundleName)480 int32_t BundleManagerInternal::GetBundleNameById(const std::string& networkId,
481     const uint16_t& bundleNameId, std::string& bundleName)
482 {
483     HILOGD("called.");
484     bool result = DmsBmStorage::GetInstance()->GetDistributedBundleName(networkId, bundleNameId, bundleName);
485     if (!result) {
486         HILOGE("failed to get bundleName by bundleNameId, try syncing");
487         DmsKvSyncE2E::GetInstance()->PushAndPullData(networkId);
488         return CAN_NOT_FOUND_ABILITY_ERR;
489     }
490     HILOGD("end.");
491     return ERR_OK;
492 }
493 
GetApplicationInfoFromBms(const std::string & bundleName,const AppExecFwk::BundleFlag flag,const int32_t userId,AppExecFwk::ApplicationInfo & appInfo)494 int32_t BundleManagerInternal::GetApplicationInfoFromBms(const std::string& bundleName,
495     const AppExecFwk::BundleFlag flag, const int32_t userId, AppExecFwk::ApplicationInfo &appInfo)
496 {
497     auto bundleMgr = GetBundleManager();
498     if (bundleMgr == nullptr) {
499         HILOGE("failed to get bms");
500         return INVALID_PARAMETERS_ERR;
501     }
502     std::string identity = IPCSkeleton::ResetCallingIdentity();
503     bundleMgr->GetApplicationInfo(bundleName, flag, userId, appInfo);
504     IPCSkeleton::SetCallingIdentity(identity);
505     return ERR_OK;
506 }
507 
QueryOsAccount(int32_t & activeAccountId)508 ErrCode BundleManagerInternal::QueryOsAccount(int32_t& activeAccountId)
509 {
510 #ifdef OS_ACCOUNT_PART
511     std::vector<int32_t> ids;
512     ErrCode err = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
513     if (err != ERR_OK || ids.empty()) {
514         HILOGE("QueryActiveOsAccountIds passing param invalid or return error!, err : %{public}d", err);
515         return INVALID_PARAMETERS_ERR;
516     }
517     activeAccountId = ids[0];
518 #endif
519     return ERR_OK;
520 }
521 } // namespace DistributedSchedule
522 } // namespace OHOS
523