1 /*
2  * Copyright (c) 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 "edm_bundle_manager_impl.h"
17 
18 #include "bundle_mgr_proxy.h"
19 #include "bundle_mgr_interface.h"
20 #include "system_ability_definition.h"
21 
22 #include "edm_log.h"
23 #include "edm_sys_manager.h"
24 
25 namespace OHOS {
26 namespace EDM {
GetNameForUid(int uid, std::string &name)27 ErrCode EdmBundleManagerImpl::GetNameForUid(int uid, std::string &name)
28 {
29     auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
30     sptr<AppExecFwk::IBundleMgr> proxy = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
31     if (proxy && !proxy->GetNameForUid(uid, name)) {
32         EDMLOGI("EdmBundleManagerImpl::GetNameForUid success.");
33         return ERR_OK;
34     }
35     EDMLOGE("EdmBundleManagerImpl::GetNameForUid GetBundleMgr failed.");
36     return ERR_BUNDLE_SERVICE_ABNORMALLY;
37 }
38 
QueryExtensionAbilityInfos(const AAFwk::Want &want, const AppExecFwk::ExtensionAbilityType &extensionType, int32_t flag, int32_t userId, std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos)39 bool EdmBundleManagerImpl::QueryExtensionAbilityInfos(const AAFwk::Want &want,
40     const AppExecFwk::ExtensionAbilityType &extensionType, int32_t flag, int32_t userId,
41     std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos)
42 {
43     auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
44     sptr<AppExecFwk::IBundleMgr> proxy = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
45     if (proxy && proxy->QueryExtensionAbilityInfos(want, extensionType, flag, userId, extensionInfos)) {
46         EDMLOGI("EdmBundleManagerImpl::QueryExtensionAbilityInfos success.");
47         return true;
48     }
49     EDMLOGE("EdmBundleManagerImpl::QueryExtensionAbilityInfos GetBundleMgr failed.");
50     return false;
51 }
52 
GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, AppExecFwk::BundleInfo &bundleInfo, int32_t userId)53 bool EdmBundleManagerImpl::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag,
54     AppExecFwk::BundleInfo &bundleInfo, int32_t userId)
55 {
56     auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
57     sptr<AppExecFwk::IBundleMgr> proxy = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
58     if (proxy && proxy->GetBundleInfo(bundleName, flag, bundleInfo, userId)) {
59         EDMLOGI("EdmBundleManagerImpl::GetBundleInfo success.");
60         return true;
61     }
62     EDMLOGE("EdmBundleManagerImpl::GetBundleInfo GetBundleMgr failed.");
63     return false;
64 }
65 } // namespace EDM
66 } // namespace OHOS