1 /* 2 * Copyright (c) 2021-2022 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H 18 19 #include "appexecfwk_errors.h" 20 #include "bundle_constants.h" 21 #include "bundle_info.h" 22 #include "bundle_pack_info.h" 23 #include "extension_ability_info.h" 24 #include "hap_module_info.h" 25 #include "want.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class BundleMgrClientImpl; 30 using Want = OHOS::AAFwk::Want; 31 32 class BundleMgrClient { 33 public: 34 BundleMgrClient(); 35 virtual ~BundleMgrClient(); 36 37 bool GetBundleNameForUid(const int uid, std::string &bundleName); 38 bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, 39 int32_t userId = Constants::UNSPECIFIED_USERID); 40 ErrCode GetBundlePackInfo(const std::string &bundleName, const BundlePackFlag flag, BundlePackInfo &bundlePackInfo, 41 int32_t userId = Constants::UNSPECIFIED_USERID); 42 43 /** 44 * @brief Obtain the profile which are deploied in the Metadata in the bundle. 45 * @param bundleName Indicates the bundle name of the bundle. 46 * @param hapName Indicates the hap name of the bundle. 47 * @param hapModuleInfo Indicates the information of the hap. 48 * @return Returns true if this function is successfully called; returns false otherwise. 49 */ 50 bool GetHapModuleInfo(const std::string &bundleName, const std::string &hapName, HapModuleInfo &hapModuleInfo); 51 /** 52 * @brief Obtain the profile which are deploied in the Metadata in the bundle. 53 * @param hapModuleInfo Indicates the information of a hap of this bundle. 54 * @param MetadataName Indicates the name of the Metadata. 55 * @param profileInfos Indicates the obtained profiles in json string. 56 * @return Returns true if this function is successfully called; returns false otherwise. 57 */ 58 bool GetResConfigFile(const HapModuleInfo &hapModuleInfo, const std::string &metadataName, 59 std::vector<std::string> &profileInfos) const; 60 /** 61 * @brief Obtain the profile which are deploied in the Metadata in the bundle. 62 * @param extensionInfo Indicates the information of the extension info of the bundle. 63 * @param MetadataName Indicates the name of the Metadata. 64 * @param profileInfos Indicates the obtained profiles in json string. 65 * @return Returns true if this function is successfully called; returns false otherwise. 66 */ 67 bool GetResConfigFile(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName, 68 std::vector<std::string> &profileInfos) const; 69 /** 70 * @brief Obtain the profile which are deploied in the Metadata in the bundle. 71 * @param abilityInfo Indicates the information of the ability info of the bundle. 72 * @param MetadataName Indicates the name of the Metadata. 73 * @param profileInfos Indicates the obtained profiles in json string. 74 * @return Returns true if this function is successfully called; returns false otherwise. 75 */ 76 bool GetResConfigFile(const AbilityInfo &abilityInfo, const std::string &metadataName, 77 std::vector<std::string> &profileInfos) const; 78 79 std::vector<std::string> GetAccessibleAppCodePaths(int32_t userId); 80 81 bool GetProfileFromExtension(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName, 82 std::vector<std::string> &profileInfos) const; 83 bool GetProfileFromAbility(const AbilityInfo &abilityInfo, const std::string &metadataName, 84 std::vector<std::string> &profileInfos) const; 85 bool GetProfileFromHap(const HapModuleInfo &hapModuleInfo, const std::string &metadataName, 86 std::vector<std::string> &profileInfos) const; 87 /** 88 * @brief Install sandbox application. 89 * @param bundleName Indicates the bundle name of the sandbox application to be install. 90 * @param dlpType Indicates type of the sandbox application. 91 * @param userId Indicates the sandbox application will be installed under which user id. 92 * @param appIndex Indicates the appIndex of the sandbox application installed under which user id. 93 * @return Returns appIndex of sandbox application if successfully, otherwise returns 0. 94 */ 95 ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, int32_t &appIndex); 96 97 /** 98 * @brief Uninstall sandbox application. 99 * @param bundleName Indicates the bundle name of the sandbox application to be install. 100 * @param appIndex Indicates application index of the sandbox application. 101 * @param userId Indicates the sandbox application will be uninstall under which user id. 102 * @return Returns true if the sandbox application is installed successfully; returns false otherwise. 103 */ 104 ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId); 105 106 ErrCode GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info); 107 108 ErrCode GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 109 AbilityInfo &abilityInfo); 110 ErrCode GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 111 std::vector<ExtensionAbilityInfo> &extensionInfos); 112 ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, 113 HapModuleInfo &hapModuleInfo); 114 115 private: 116 std::shared_ptr<BundleMgrClientImpl> impl_; 117 }; 118 } // namespace AppExecFwk 119 } // namespace OHOS 120 121 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H 122