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