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