• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "distributed_helper.h"
17 
18 #include "app_log_wrapper.h"
19 #include "bundle_errors.h"
20 #include "business_error.h"
21 #include "common_func.h"
22 #include "distributed_bms_interface.h"
23 #include "distributed_bms_proxy.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 
GetDistributedBundleMgr()30 static OHOS::sptr<OHOS::AppExecFwk::IDistributedBms> GetDistributedBundleMgr()
31 {
32     APP_LOGD("GetDistributedBundleMgr start");
33     auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
34     if (samgr == nullptr) {
35         APP_LOGE("GetDistributedBundleMgr samgr is nullptr");
36         return nullptr;
37     }
38     auto remoteObject = samgr->GetSystemAbility(OHOS::DISTRIBUTED_BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
39     if (remoteObject == nullptr) {
40         APP_LOGE("GetDistributedBundleMgr remoteObject is nullptr");
41         return nullptr;
42     }
43     auto distributeBundleMgr = OHOS::iface_cast<IDistributedBms>(remoteObject);
44     if (distributeBundleMgr == nullptr) {
45         APP_LOGE("GetDistributedBundleMgr distributeBundleMgr is nullptr");
46         return nullptr;
47     }
48     return distributeBundleMgr;
49 }
50 
InnerGetRemoteAbilityInfo(const std::vector<ElementName> & elementNames,const std::string & locale,bool isArray,std::vector<RemoteAbilityInfo> & remoteAbilityInfos)51 int32_t DistributedHelper::InnerGetRemoteAbilityInfo(const std::vector<ElementName> &elementNames,
52     const std::string &locale, bool isArray, std::vector<RemoteAbilityInfo> &remoteAbilityInfos)
53 {
54     if (elementNames.size() == 0) {
55         APP_LOGE("InnerGetRemoteAbilityInfos elementNames is empty");
56         return ERROR_PARAM_CHECK_ERROR;
57     }
58     auto iDistBundleMgr = GetDistributedBundleMgr();
59     if (iDistBundleMgr == nullptr) {
60         APP_LOGE("can not get iDistBundleMgr");
61         return ERROR_DISTRIBUTED_SERVICE_NOT_RUNNING;
62     }
63     int32_t result;
64     if (isArray) {
65         result = iDistBundleMgr->GetRemoteAbilityInfos(elementNames, locale, remoteAbilityInfos);
66     } else {
67         RemoteAbilityInfo remoteAbilityInfo;
68         result = iDistBundleMgr->GetRemoteAbilityInfo(elementNames[0], locale, remoteAbilityInfo);
69         remoteAbilityInfos.push_back(remoteAbilityInfo);
70     }
71     if (result != 0) {
72         APP_LOGE("InnerGetRemoteAbilityInfo failed");
73     }
74     return CommonFunc::ConvertErrCode(result);
75 }
76 } // AppExecFwk
77 } // OHOS