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