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