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