1 /* 2 * Copyright (c) 2023 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 #ifndef OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H 17 #define OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H 18 19 #include <singleton.h> 20 21 #include "bundle_mgr_interface.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 using Want = OHOS::AAFwk::Want; 26 27 class BundleMgrHelper : public std::enable_shared_from_this<BundleMgrHelper> { 28 public: 29 DISALLOW_COPY_AND_MOVE(BundleMgrHelper); 30 void PreConnect(); 31 ErrCode GetNameForUid(const int32_t uid, std::string &name); 32 ErrCode GetNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex); 33 bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId); 34 ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, int32_t &appIndex); 35 ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId); 36 ErrCode GetUninstalledBundleInfo(const std::string bundleName, BundleInfo &bundleInfo); 37 ErrCode GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info); 38 ErrCode GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 39 AbilityInfo &abilityInfo); 40 ErrCode GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 41 std::vector<ExtensionAbilityInfo> &extensionInfos); 42 ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, 43 HapModuleInfo &hapModuleInfo); 44 bool GetBundleInfo(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId); 45 std::string GetAppIdByBundleName(const std::string &bundleName, const int32_t userId); 46 bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo); 47 std::string GetAbilityLabel(const std::string &bundleName, const std::string &abilityName); 48 std::string GetAppType(const std::string &bundleName); 49 ErrCode GetBaseSharedBundleInfos( 50 const std::string &bundleName, std::vector<BaseSharedBundleInfo> &baseSharedBundleInfos, 51 GetDependentBundleInfoFlag flag = GetDependentBundleInfoFlag::GET_APP_CROSS_HSP_BUNDLE_INFO); 52 ErrCode GetBundleInfoForSelf(int32_t flags, BundleInfo &bundleInfo); 53 ErrCode GetDependentBundleInfo(const std::string &sharedBundleName, BundleInfo &sharedBundleInfo, 54 GetDependentBundleInfoFlag flag = GetDependentBundleInfoFlag::GET_APP_CROSS_HSP_BUNDLE_INFO); 55 bool GetGroupDir(const std::string &dataGroupId, std::string &dir); 56 sptr<IOverlayManager> GetOverlayManagerProxy(); 57 bool QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo); 58 bool QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo); 59 bool GetBundleInfos(int32_t flags, 60 std::vector<BundleInfo> &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID); 61 sptr<IQuickFixManager> GetQuickFixManagerProxy(); 62 bool ProcessPreload(const Want &want); 63 sptr<IAppControlMgr> GetAppControlProxy(); 64 bool QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId, 65 std::vector<ExtensionAbilityInfo> &extensionInfos); 66 ErrCode GetBundleInfoV9( 67 const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId); 68 bool GetApplicationInfo( 69 const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo); 70 bool GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo); 71 bool GetApplicationInfoWithAppIndex(const std::string &appName, int32_t appIndex, 72 int32_t userId, ApplicationInfo &appInfo); 73 ErrCode GetJsonProfile(ProfileType profileType, const std::string &bundleName, 74 const std::string &moduleName, std::string &profile, int32_t userId = Constants::UNSPECIFIED_USERID); 75 bool UnregisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback); 76 bool QueryExtensionAbilityInfoByUri( 77 const std::string &uri, int32_t userId, ExtensionAbilityInfo &extensionAbilityInfo); 78 bool ImplicitQueryInfoByPriority(const Want &want, int32_t flags, int32_t userId, 79 AbilityInfo &abilityInfo, ExtensionAbilityInfo &extensionInfo); 80 bool QueryAbilityInfoByUri(const std::string &abilityUri, int32_t userId, AbilityInfo &abilityInfo); 81 bool QueryAbilityInfo(const Want &want, 82 int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr<IRemoteObject> &callBack); 83 void UpgradeAtomicService(const Want &want, int32_t userId); 84 bool ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault, 85 std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos); 86 bool CleanBundleDataFiles(const std::string &bundleName, int32_t userId, int32_t appCloneIndex); 87 bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::vector<DataGroupInfo> &infos); 88 bool RegisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback); 89 bool GetBundleInfos( 90 const BundleFlag flag, std::vector<BundleInfo> &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID); 91 bool GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo); 92 bool QueryAppGalleryBundleName(std::string &bundleName); 93 ErrCode GetUidByBundleName(const std::string &bundleName, int32_t userId, int32_t appCloneIndex); 94 ErrCode QueryExtensionAbilityInfosOnlyWithTypeName(const std::string &extensionTypeName, 95 const uint32_t flag, const int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos); 96 sptr<IDefaultApp> GetDefaultAppProxy(); 97 ErrCode GetLaunchWantForBundle(const std::string &bundleName, Want &want, int32_t userId); 98 ErrCode QueryCloneAbilityInfo(const ElementName &element, int32_t flags, int32_t appCloneIndex, 99 AbilityInfo &abilityInfo, int32_t userId); 100 ErrCode GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex, 101 BundleInfo &bundleInfo, int32_t userId); 102 ErrCode QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName &element, int32_t flags, int32_t appCloneIndex, 103 ExtensionAbilityInfo &extensionInfo, int32_t userId); 104 ErrCode GetCloneAppIndexes(const std::string &bundleName, std::vector<int32_t> &appIndexes, int32_t userId); 105 ErrCode GetSignatureInfoByBundleName(const std::string &bundleName, SignatureInfo &signatureInfo); 106 107 private: 108 sptr<IBundleMgr> Connect(); 109 sptr<IBundleInstaller> ConnectBundleInstaller(); 110 void OnDeath(); 111 std::string ParseBundleNameByAppId(const std::string &appId) const; 112 113 private: 114 DECLARE_DELAYED_SINGLETON(BundleMgrHelper) 115 std::mutex mutex_; 116 sptr<IBundleMgr> bundleMgr_; 117 sptr<IBundleInstaller> bundleInstaller_; 118 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 119 }; 120 } // namespace AppExecFwk 121 } // namespace OHOS 122 #endif // OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H