• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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      * @return Returns true if this function is successfully called; returns false otherwise.
60      */
61     bool GetResConfigFile(const HapModuleInfo &hapModuleInfo, const std::string &metadataName,
62     std::vector<std::string> &profileInfos) const;
63     /**
64      * @brief Obtain the profile which are deploied in the Metadata in the bundle.
65      * @param extensionInfo Indicates the information of the extension info of the bundle.
66      * @param MetadataName Indicates the name of the Metadata.
67      * @param profileInfos Indicates the obtained profiles in json string.
68      * @return Returns true if this function is successfully called; returns false otherwise.
69      */
70     bool GetResConfigFile(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName,
71         std::vector<std::string> &profileInfos) const;
72     /**
73      * @brief Obtain the profile which are deploied in the Metadata in the bundle.
74      * @param abilityInfo Indicates the information of the ability info of the bundle.
75      * @param MetadataName Indicates the name of the Metadata.
76      * @param profileInfos Indicates the obtained profiles in json string.
77      * @return Returns true if this function is successfully called; returns false otherwise.
78      */
79     bool GetResConfigFile(const AbilityInfo &abilityInfo, const std::string &metadataName,
80         std::vector<std::string> &profileInfos) const;
81 
82     bool GetProfileFromExtension(const ExtensionAbilityInfo &extensionInfo, const std::string &metadataName,
83         std::vector<std::string> &profileInfos) const;
84     bool GetProfileFromAbility(const AbilityInfo &abilityInfo, const std::string &metadataName,
85         std::vector<std::string> &profileInfos) const;
86     bool GetProfileFromHap(const HapModuleInfo &hapModuleInfo, const std::string &metadataName,
87         std::vector<std::string> &profileInfos) const;
88     /**
89      * @brief Install sandbox application.
90      * @param bundleName Indicates the bundle name of the sandbox application to be install.
91      * @param dlpType Indicates type of the sandbox application.
92      * @param userId Indicates the sandbox application will be installed under which user id.
93      * @param appIndex Indicates the appIndex of the sandbox application installed under which user id.
94      * @return Returns appIndex of sandbox application if successfully, otherwise returns 0.
95      */
96     ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, int32_t &appIndex);
97 
98     /**
99      * @brief Uninstall sandbox application.
100      * @param bundleName Indicates the bundle name of the sandbox application to be install.
101      * @param appIndex Indicates application index of the sandbox application.
102      * @param userId Indicates the sandbox application will be uninstall under which user id.
103      * @return Returns true if the sandbox application is installed successfully; returns false otherwise.
104      */
105     ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId);
106 
107     ErrCode GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info);
108 
109     ErrCode GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId,
110         AbilityInfo &abilityInfo);
111     ErrCode GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags, int32_t userId,
112         std::vector<ExtensionAbilityInfo> &extensionInfos);
113     ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
114         HapModuleInfo &hapModuleInfo);
115     ErrCode GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex, std::string &dataDir);
116     ErrCode GetAllBundleDirs(int32_t userId, std::vector<BundleDir> &bundleDirs);
117 
118 private:
119     static std::shared_ptr<BundleMgrClientImpl> impl_;
120 };
121 }  // namespace AppExecFwk
122 }  // namespace OHOS
123 
124 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H
125