1 /* 2 * Copyright (c) 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_IMPL_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_IMPL_H 18 19 #include <shared_mutex> 20 21 #include "appexecfwk_errors.h" 22 #include "application_info.h" 23 #include "bundle_info.h" 24 #include "bundle_pack_info.h" 25 #include "bundle_mgr_interface.h" 26 #include "extension_ability_info.h" 27 #include "hap_module_info.h" 28 #ifdef GLOBAL_RESMGR_ENABLE 29 #include "resource_manager.h" 30 #endif 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 using Want = OHOS::AAFwk::Want; 35 36 class BundleMgrClientImpl : public std::enable_shared_from_this<BundleMgrClientImpl> { 37 public: 38 BundleMgrClientImpl(); 39 virtual ~BundleMgrClientImpl(); 40 41 ErrCode GetNameForUid(const int uid, std::string &name); 42 bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId); 43 ErrCode GetBundlePackInfo( 44 const std::string &bundleName, const BundlePackFlag flag, BundlePackInfo &bundlePackInfo, int32_t userId); 45 bool GetHapModuleInfo(const std::string &bundleName, const std::string &hapName, HapModuleInfo &hapModuleInfo); 46 bool GetResConfigFile(const HapModuleInfo &hapModuleInfo, const std::string &metadataName, 47 std::vector<std::string> &profileInfos) const; 48 bool GetResConfigFile(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName, 49 std::vector<std::string> &profileInfos) const; 50 bool GetResConfigFile(const AbilityInfo &abilityInfo, const std::string &metadataName, 51 std::vector<std::string> &profileInfos) const; 52 ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, int32_t &appIndex); 53 ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId); 54 ErrCode GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info); 55 bool GetProfileFromExtension(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName, 56 std::vector<std::string> &profileInfos) const; 57 bool GetProfileFromAbility(const AbilityInfo &abilityInfo, const std::string &metadataName, 58 std::vector<std::string> &profileInfos) const; 59 bool GetProfileFromHap(const HapModuleInfo &hapModuleInfo, const std::string &metadataName, 60 std::vector<std::string> &profileInfos) const; 61 ErrCode GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 62 AbilityInfo &abilityInfo); 63 ErrCode GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags, int32_t userId, 64 std::vector<ExtensionAbilityInfo> &extensionInfos); 65 ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, 66 HapModuleInfo &hapModuleInfo); 67 ErrCode CreateBundleDataDir(int32_t userId); 68 ErrCode GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex, std::string &dataDir); 69 70 private: 71 ErrCode Connect(); 72 void OnDeath(); 73 bool ConvertResourcePath(const std::string &bundleName, std::string &resPath, bool isCompressed) const; 74 bool GetResProfileByMetadata(const std::vector<Metadata> &metadata, const std::string &metadataName, 75 const std ::string &resourcePath, bool isCompressed, std::vector<std::string> &profileInfos) const; 76 #ifdef GLOBAL_RESMGR_ENABLE 77 std::shared_ptr<Global::Resource::ResourceManager> InitResMgr(const std::string &resourcePath) const; 78 bool GetResFromResMgr(const std::string &resName, const std::shared_ptr<Global::Resource::ResourceManager> &resMgr, 79 bool isCompressed, std::vector<std::string> &profileInfos) const; 80 #endif 81 bool IsFileExisted(const std::string &filePath) const; 82 bool TransformFileToJsonString(const std::string &resPath, std::string &profile) const; 83 84 private: 85 std::shared_mutex mutex_; 86 sptr<IBundleMgr> bundleMgr_; 87 sptr<IBundleInstaller> bundleInstaller_; 88 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 89 }; 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H