1 /*
2  * Copyright (c) 2021-2024 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_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_MGR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_MGR_H
18 
19 #include <atomic>
20 #include <map>
21 #include <memory>
22 #include <mutex>
23 #include <optional>
24 #include <set>
25 #include <shared_mutex>
26 #include <string>
27 
28 #include "want.h"
29 
30 #include "ability_info.h"
31 #include "aot/aot_args.h"
32 #include "application_info.h"
33 #include "app_provision_info.h"
34 #include "bundle_data_storage_interface.h"
35 #include "bundle_event_callback_interface.h"
36 #include "bundle_promise.h"
37 #include "bundle_sandbox_app_helper.h"
38 #include "bundle_state_storage.h"
39 #include "bundle_status_callback_interface.h"
40 #include "common_event_data.h"
41 #include "ffrt.h"
42 #include "inner_bundle_clone_info.h"
43 #include "inner_bundle_info.h"
44 #include "inner_bundle_user_info.h"
45 #include "ipc/create_dir_param.h"
46 #include "uninstall_data_mgr_storage_rdb.h"
47 #include "module_info.h"
48 #include "preinstall_data_storage_interface.h"
49 #include "router_data_storage_interface.h"
50 #include "shortcut_data_storage_interface.h"
51 #ifdef GLOBAL_RESMGR_ENABLE
52 #include "resource_manager.h"
53 #endif
54 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
55 #include "element.h"
56 #endif
57 
58 namespace OHOS {
59 namespace AppExecFwk {
60 enum class InstallState {
61     INSTALL_START = 1,
62     INSTALL_SUCCESS,
63     INSTALL_FAIL,
64     UNINSTALL_START,
65     UNINSTALL_SUCCESS,
66     UNINSTALL_FAIL,
67     UPDATING_START,
68     UPDATING_SUCCESS,
69     UPDATING_FAIL,
70     ROLL_BACK,
71     USER_CHANGE,
72 };
73 
74 class BundleDataMgr {
75 public:
76     using Want = OHOS::AAFwk::Want;
77 
78     // init state transfer map data.
79     BundleDataMgr();
80     virtual ~BundleDataMgr();
81 
82     /**
83      * @brief Boot query persistent storage.
84      * @return Returns true if this function is successfully called; returns false otherwise.
85      */
86     bool LoadDataFromPersistentStorage();
87     /**
88      * @brief Update internal state for whole bundle.
89      * @param bundleName Indicates the bundle name.
90      * @param state Indicates the install state to be set.
91      * @return Returns true if this function is successfully called; returns false otherwise.
92      */
93     bool UpdateBundleInstallState(const std::string &bundleName, const InstallState state);
94     /**
95      * @brief Add new InnerBundleInfo.
96      * @param bundleName Indicates the bundle name.
97      * @param info Indicates the InnerBundleInfo object to be save.
98      * @return Returns true if this function is successfully called; returns false otherwise.
99      */
100     bool AddInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info);
101     /**
102      * @brief Add new module info to an exist InnerBundleInfo.
103      * @param bundleName Indicates the bundle name.
104      * @param newInfo Indicates the new InnerBundleInfo object.
105      * @param oldInfo Indicates the old InnerBundleInfo object.
106      * @param isUpgrade Indicates whether the module is upgraded.
107      * @return Returns true if this function is successfully called; returns false otherwise.
108      */
109     bool AddNewModuleInfo(const std::string &bundleName, const InnerBundleInfo &newInfo,
110         InnerBundleInfo &oldInfo, bool isUpgrade = false);
111     /**
112      * @brief Remove module info from an exist InnerBundleInfo.
113      * @param bundleName Indicates the bundle name.
114      * @param modulePackage Indicates the module Package.
115      * @param oldInfo Indicates the old InnerBundleInfo object.
116      * @return Returns true if this function is successfully called; returns false otherwise.
117      */
118     bool RemoveModuleInfo(const std::string &bundleName, const std::string &modulePackage, InnerBundleInfo &oldInfo);
119 
120     bool RemoveHspModuleByVersionCode(int32_t versionCode, InnerBundleInfo &info);
121     /**
122      * @brief Update module info of an exist module.
123      * @param bundleName Indicates the bundle name.
124      * @param newInfo Indicates the new InnerBundleInfo object.
125      * @param oldInfo Indicates the old InnerBundleInfo object.
126      * @param isUpgrade Indicates whether the module is upgraded.
127      * @return Returns true if this function is successfully called; returns false otherwise.
128      */
129     bool UpdateInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &newInfo,
130         InnerBundleInfo &oldInfo, bool isUpgrade = false);
131 
132     bool UpdateInnerBundleInfo(const InnerBundleInfo &innerBundleInfo);
133     /**
134      * @brief Get an InnerBundleInfo if exist (will change the status to DISABLED).
135      * @param bundleName Indicates the bundle name.
136      * @param info Indicates the obtained InnerBundleInfo object.
137      * @return Returns true if this function is successfully called; returns false otherwise.
138      */
139     bool GetInnerBundleInfoWithDisable(const std::string &bundleName, InnerBundleInfo &info);
140     /**
141      * @brief Generate UID and GID for a bundle.
142      * @param innerBundleUserInfo Indicates the InnerBundleUserInfo object.
143      * @return Returns true if this function is successfully called; returns false otherwise.
144      */
145     bool GenerateUidAndGid(InnerBundleUserInfo &innerBundleUserInfo);
146     /**
147      * @brief Recycle uid and gid .
148      * @param info Indicates the InnerBundleInfo object.
149      */
150     void RecycleUidAndGid(const InnerBundleInfo &info);
151     /**
152      * @brief Query the AbilityInfo by the given Want.
153      * @param want Indicates the information of the ability.
154      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
155      * @param userId Indicates the user ID.
156      * @param abilityInfo Indicates the obtained AbilityInfo object.
157      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
158      */
159     bool QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo,
160         int32_t appIndex = 0) const;
161     /**
162      * @brief Query a AbilityInfo of list by the given Want.
163      * @param want Indicates the information of the ability.
164      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
165      * @param userId Indicates the user ID.
166      * @param abilityInfos Indicates the obtained AbilityInfo of list.
167      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
168      */
169     bool QueryAbilityInfos(
170         const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
171     /**
172      * @brief Query a AbilityInfo of list by the given Want.
173      * @param want Indicates the information of the ability.
174      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
175      * @param userId Indicates the user ID.
176      * @param abilityInfos Indicates the obtained AbilityInfo of list.
177      * @return Returns ERR_OK if the AbilityInfo is successfully obtained; returns errCode otherwise.
178      */
179     ErrCode QueryAbilityInfosV9(
180         const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
181     /**
182      * @brief Query a AbilityInfo of list by the given Want.
183      * @param want Indicates the information of the ability.
184      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
185      * @param userId Indicates the user ID.
186      * @param abilityInfos Indicates the obtained AbilityInfo of list.
187      * @return Returns ERR_OK if the AbilityInfo is successfully obtained; returns errCode otherwise.
188      */
189     ErrCode BatchQueryAbilityInfos(
190         const std::vector<Want> &wants, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
191     /**
192      * @brief Query Launcher AbilityInfo of list by the given Want.
193      * @param want Indicates the information of the ability.
194      * @param userId Indicates the user ID.
195      * @param abilityInfos Indicates the obtained AbilityInfo of list.
196      * @return Returns ERR_OK if the AbilityInfo is successfully obtained; returns errCode otherwise.
197      */
198     ErrCode QueryLauncherAbilityInfos(
199         const Want &want, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
200     /**
201      * @brief Query all match launcher ability infos by given wants.
202      * @param want Indicates the match infomation for abilities.
203      * @param info Indicates the bundleInfo.
204      * @param abilityInfo Indicates the obtained AbilityInfo of list.
205      * @param userId Indicates the user ID.
206      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
207      */
208     void GetMatchLauncherAbilityInfos(const Want& want, const InnerBundleInfo& info,
209         std::vector<AbilityInfo>& abilityInfos, int64_t installTime,
210         int32_t userId = Constants::UNSPECIFIED_USERID) const;
211     /**
212      * @brief Query the AbilityInfo by ability.uri in config.json.
213      * @param abilityUri Indicates the uri of the ability.
214      * @param abilityInfos Indicates the obtained AbilityInfos object.
215      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
216      */
217     bool QueryAbilityInfosByUri(const std::string &abilityUri, std::vector<AbilityInfo> &abilityInfos);
218     /**
219      * @brief Query the AbilityInfo by ability.uri in config.json.
220      * @param abilityUri Indicates the uri of the ability.
221      * @param userId Indicates the user ID.
222      * @param abilityInfo Indicates the obtained AbilityInfo object.
223      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
224      */
225     bool QueryAbilityInfoByUri(
226         const std::string &abilityUri, int32_t userId, AbilityInfo &abilityInfo) const;
227     /**
228      * @brief Obtains the ApplicationInfo based on a given bundle name.
229      * @param appName Indicates the application bundle name to be queried.
230      * @param flags Indicates the flag used to specify information contained
231      *             in the ApplicationInfo object that will be returned.
232      * @param userId Indicates the user ID.
233      * @param appInfo Indicates the obtained ApplicationInfo object.
234      * @return Returns true if the application is successfully obtained; returns false otherwise.
235      */
236     bool GetApplicationInfo(
237         const std::string &appName, int32_t flags, const int userId, ApplicationInfo &appInfo) const;
238     /**
239      * @brief Obtains the ApplicationInfo based on a given bundle name.
240      * @param appName Indicates the application bundle name to be queried.
241      * @param flags Indicates the flag used to specify information contained
242      *             in the ApplicationInfo object that will be returned.
243      * @param userId Indicates the user ID.
244      * @param appInfo Indicates the obtained ApplicationInfo object.
245      * @return Returns ERR_OK if the application is successfully obtained; returns error code otherwise.
246      */
247     ErrCode GetApplicationInfoV9(
248         const std::string &appName, int32_t flags, int32_t userId,
249         ApplicationInfo &appInfo, const int32_t appIndex = 0) const;
250     /**
251      * @brief Obtains the ApplicationInfo based on a given bundle name.
252      * @param appName Indicates the application bundle name to be queried.
253      * @param flags Indicates the flag used to specify information contained
254      *             in the ApplicationInfo object that will be returned.
255      * @param userId Indicates the user ID.
256      * @param appInfo Indicates the obtained ApplicationInfo object.
257      * @return Returns ERR_OK if the application is successfully obtained; returns error code otherwise.
258      */
259     ErrCode GetApplicationInfoWithResponseId(
260         const std::string &appName, int32_t flags, int32_t &userId, ApplicationInfo &appInfo) const;
261     /**
262      * @brief Obtains information about all installed applications of a specified user.
263      * @param flags Indicates the flag used to specify information contained
264      *             in the ApplicationInfo objects that will be returned.
265      * @param userId Indicates the user ID.
266      * @param appInfos Indicates all of the obtained ApplicationInfo objects.
267      * @return Returns true if the application is successfully obtained; returns false otherwise.
268      */
269     bool GetApplicationInfos(
270         int32_t flags, const int userId, std::vector<ApplicationInfo> &appInfos) const;
271     /**
272      * @brief Obtains information about all installed applications of a specified user.
273      * @param flags Indicates the flag used to specify information contained
274      *             in the ApplicationInfo objects that will be returned.
275      * @param userId Indicates the user ID.
276      * @param appInfos Indicates all of the obtained ApplicationInfo objects.
277      * @return Returns ERR_OK if the application is successfully obtained; returns error code otherwise.
278      */
279     ErrCode GetApplicationInfosV9(
280         int32_t flags, int32_t userId, std::vector<ApplicationInfo> &appInfos) const;
281     /**
282      * @brief Obtains BundleInfo of all bundles available in the system.
283      * @param flags Indicates the flag used to specify information contained in the BundleInfo that will be returned.
284      * @param bundleInfos Indicates all of the obtained BundleInfo objects.
285      * @param userId Indicates the user ID.
286      * @return Returns true if the BundleInfos is successfully obtained; returns false otherwise.
287      */
288     bool GetBundleInfos(int32_t flags,
289         std::vector<BundleInfo> &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID) const;
290     /**
291      * @brief Obtains BundleInfo of all bundles available in the system.
292      * @param flags Indicates the flag used to specify information contained in the BundleInfo that will be returned.
293      * @param bundleInfos Indicates all of the obtained BundleInfo objects.
294      * @param userId Indicates the user ID.
295      * @return Returns ERR_OK if the BundleInfos is successfully obtained; returns error code otherwise.
296      */
297     ErrCode GetBundleInfosV9(int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId) const;
298     /**
299      * @brief Obtains the BundleInfo based on a given bundle name.
300      * @param bundleName Indicates the application bundle name to be queried.
301      * @param flags Indicates the information contained in the BundleInfo object to be returned.
302      * @param bundleInfo Indicates the obtained BundleInfo object.
303      * @param userId Indicates the user ID.
304      * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise.
305      */
306     bool GetBundleInfo(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo,
307         int32_t userId = Constants::UNSPECIFIED_USERID) const;
308     /**
309      * @brief Obtains the BundleInfo based on a given bundle name.
310      * @param bundleName Indicates the application bundle name to be queried.
311      * @param flags Indicates the information contained in the BundleInfo object to be returned.
312      * @param bundleInfo Indicates the obtained BundleInfo object.
313      * @param userId Indicates the user ID.
314      * @param appIndex Indicates the app index.
315      * @return Returns ERR_OK if the BundleInfo is successfully obtained; returns error code otherwise.
316      */
317     ErrCode GetBundleInfoV9(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo,
318         int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) const;
319     /**
320      * @brief Batch obtains the BundleInfos based on a given bundle name list.
321      * @param bundleNames Indicates the application bundle name list to be queried.
322      * @param flags Indicates the information contained in the BundleInfo object to be returned.
323      * @param bundleInfos Indicates the obtained BundleInfo list object.
324      * @param userId Indicates the user ID.
325      * @return Returns ERR_OK if the BundleInfo is successfully obtained; returns error code otherwise.
326      */
327     void BatchGetBundleInfo(const std::vector<std::string> &bundleNames, int32_t flags,
328         std::vector<BundleInfo> &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID) const;
329     /**
330      * @brief Obtains the BundlePackInfo based on a given bundle name.
331      * @param bundleName Indicates the application bundle name to be queried.
332      * @param flags Indicates the information contained in the BundleInfo object to be returned.
333      * @param BundlePackInfo Indicates the obtained BundlePackInfo object.
334      * @return Returns ERR_OK if the BundlePackInfo is successfully obtained; returns other ErrCode otherwise.
335      */
336     ErrCode GetBundlePackInfo(const std::string &bundleName, int32_t flags, BundlePackInfo &bundleInfo,
337         int32_t userId = Constants::UNSPECIFIED_USERID) const;
338     /**
339      * @brief Obtains the BundleInfo of application bundles based on the specified metaData.
340      * @param metaData Indicates the metadata to get in the bundle.
341      * @param bundleInfos Indicates all of the obtained BundleInfo objects.
342      * @return Returns true if the BundleInfos is successfully obtained; returns false otherwise.
343      */
344     bool GetBundleInfosByMetaData(const std::string &metaData, std::vector<BundleInfo> &bundleInfos) const;
345     /**
346      * @brief Obtains the bundle name of a specified application based on the given UID.
347      * @param uid Indicates the uid.
348      * @param bundleName Indicates the obtained bundle name.
349      * @return Returns true if the bundle name is successfully obtained; returns false otherwise.
350      */
351     bool GetBundleNameForUid(const int32_t uid, std::string &bundleName) const;
352     /**
353      * @brief Obtains all bundle names of a specified application based on the given application UID.
354      * @param uid Indicates the uid.
355      * @param bundleNames Indicates the obtained bundle names.
356      * @return Returns true if the bundle names is successfully obtained; returns false otherwise.
357      */
358     bool GetBundlesForUid(const int uid, std::vector<std::string> &bundleNames) const;
359     /**
360      * @brief Obtains the formal name associated with the given UID.
361      * @param uid Indicates the uid.
362      * @param name Indicates the obtained formal name.
363      * @return Returns ERR_OK if called successfully; returns error code otherwise.
364      */
365     ErrCode GetNameForUid(const int uid, std::string &name) const;
366     /**
367      * @brief Obtains an array of all group IDs associated with a specified bundle.
368      * @param bundleName Indicates the bundle name.
369      * @param gids Indicates the group IDs associated with the specified bundle.
370      * @return Returns true if the gids is successfully obtained; returns false otherwise.
371      */
372     bool GetBundleGids(const std::string &bundleName, std::vector<int> &gids) const;
373     /**
374      * @brief Obtains an array of all group IDs associated with the given bundle name and UID.
375      * @param bundleName Indicates the bundle name.
376      * @param uid Indicates the uid.
377      * @param gids Indicates the group IDs associated with the specified bundle.
378      * @return Returns true if the gids is successfully obtained; returns false otherwise.
379      */
380     virtual bool GetBundleGidsByUid(const std::string &bundleName, const int &uid, std::vector<int> &gids) const;
381     /**
382      * @brief Obtains the BundleInfo of all keep-alive applications in the system.
383      * @param bundleInfos Indicates all of the obtained BundleInfo objects.
384      * @return Returns true if the BundleInfos is successfully obtained; returns false otherwise.
385      */
386     bool QueryKeepAliveBundleInfos(std::vector<BundleInfo> &bundleInfos) const;
387     /**
388      * @brief Obtains the label of a specified ability.
389      * @param bundleName Indicates the bundle name.
390      * @param moduleName Indicates the module name.
391      * @param abilityName Indicates the ability name.
392      * @param label Indicates the obtained label.
393      * @return Returns ERR_OK if the ability label is successfully obtained; returns errCode otherwise.
394      */
395     ErrCode GetAbilityLabel(const std::string &bundleName, const std::string &moduleName,
396         const std::string &abilityName, std::string &label) const;
397     /**
398      * @brief Obtains the Want for starting the main ability of an application based on the given bundle name.
399      * @param bundleName Indicates the bundle name.
400      * @param want Indicates the obtained launch Want object.
401      * @param userId Indicates the user ID.
402      * @return Returns ERR_OK if this function is successfully called; returns errCode otherwise.
403      */
404     ErrCode GetLaunchWantForBundle(
405         const std::string &bundleName, Want &want, int32_t userId = Constants::UNSPECIFIED_USERID) const;
406     /**
407      * @brief Obtain the HAP module info of a specific ability.
408      * @param abilityInfo Indicates the ability.
409      * @param userId Indicates the user ID.
410      * @param hapModuleInfo Indicates the obtained HapModuleInfo object.
411      * @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
412      */
413     bool GetHapModuleInfo(const AbilityInfo &abilityInfo,
414         HapModuleInfo &hapModuleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const;
415     /**
416      * @brief Check whether the app is system app by it's UID.
417      * @param uid Indicates the uid.
418      * @return Returns true if the bundle is a system application; returns false otherwise.
419      */
420     bool CheckIsSystemAppByUid(const int uid) const;
421     /**
422      * @brief Obtains all bundle names installed.
423      * @param bundleNames Indicates the bundle Names.
424      * @param userId Indicates the user ID.
425      * @return Returns true if have bundle installed; returns false otherwise.
426      */
427     bool GetBundleList(
428         std::vector<std::string> &bundleNames, int32_t userId = Constants::UNSPECIFIED_USERID) const;
429     /**
430      * @brief Set the bundle status disable.
431      * @param bundleName Indicates the bundle name.
432      * @return Returns true if the bundle status successfully set; returns false otherwise.
433      */
434     bool DisableBundle(const std::string &bundleName);
435     /**
436      * @brief Set the bundle status enable.
437      * @param bundleName Indicates the bundle name.
438      * @return Returns true if the bundle status successfully set; returns false otherwise.
439      */
440     bool EnableBundle(const std::string &bundleName);
441     /**
442      * @brief Get whether the application status is enabled.
443      * @param bundleName Indicates the bundle name.
444      * @param isEnable Indicates the application status is enabled.
445      * @return Returns result of the operation.
446      */
447     ErrCode IsApplicationEnabled(const std::string &bundleName,
448         int32_t appIndex, bool &isEnable, int32_t userId = Constants::UNSPECIFIED_USERID) const;
449     /**
450      * @brief Set the application status.
451      * @param bundleName Indicates the bundle name.
452      * @param isEnable Indicates the status to set.
453      * @param userId Indicates the user id.
454      * @return Returns result of the operation.
455      */
456     ErrCode SetApplicationEnabled(const std::string &bundleName, int32_t appIndex, bool isEnable,
457         int32_t userId = Constants::UNSPECIFIED_USERID);
458     /**
459      * @brief Sets whether to enable a specified ability through the proxy object.
460      * @param abilityInfo Indicates information about the ability to check.
461      * @param isEnable Indicates the ability status is enabled.
462      * @return Returns result of the operation.
463      */
464     ErrCode IsAbilityEnabled(const AbilityInfo &abilityInfo, int32_t appIndex, bool &isEnable) const;
465     /**
466      * @brief Sets whether to enable a specified ability through the proxy object.
467      * @param abilityInfo Indicates information about the ability.
468      * @param isEnabled Specifies whether to enable the ability.
469      *                 The value true means to enable it, and the value false means to disable it.
470      * @param userId Indicates the user id.
471      * @return Returns result of the operation.
472      */
473     ErrCode SetAbilityEnabled(const AbilityInfo &abilityInfo, int32_t appIndex, bool isEnabled,
474         int32_t userId = Constants::UNSPECIFIED_USERID);
475     /**
476      * @brief Register the bundle status callback function.
477      * @param bundleStatusCallback Indicates the callback object that using for notifing the bundle status.
478      * @return Returns true if this function is successfully called; returns false otherwise.
479      */
480     bool RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback);
481 
482     bool RegisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback);
483 
484     bool UnregisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback);
485     /**
486      * @brief Clear the specific bundle status callback.
487      * @param bundleStatusCallback Indicates the callback to be cleared.
488      * @return Returns true if this function is successfully called; returns false otherwise.
489      */
490     bool ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback);
491     /**
492      * @brief Unregister all the callbacks of status changed.
493      * @return Returns true if this function is successfully called; returns false otherwise.
494      */
495     bool UnregisterBundleStatusCallback();
496     /**
497      * @brief Get a mutex for locking by bundle name.
498      * @param bundleName Indicates the bundle name.
499      * @return Returns a reference of mutex that for locing by bundle name.
500      */
501     std::mutex &GetBundleMutex(const std::string &bundleName);
502     /**
503      * @brief Obtains the provision Id based on a given bundle name.
504      * @param bundleName Indicates the application bundle name to be queried.
505      * @param provisionId Indicates the provision Id to be returned.
506      * @return Returns true if the provision Id is successfully obtained; returns false otherwise.
507      */
508     bool GetProvisionId(const std::string &bundleName, std::string &provisionId) const;
509     /**
510      * @brief Obtains the app feature based on a given bundle name.
511      * @param bundleName Indicates the application bundle name to be queried.
512      * @param provisionId Indicates the app feature to be returned.
513      * @return Returns true if the app feature is successfully obtained; returns false otherwise.
514      */
515     bool GetAppFeature(const std::string &bundleName, std::string &appFeature) const;
516     /**
517      * @brief Set the flag that indicates whether initial user create successfully.
518      * @param flag Indicates the flag to be set.
519      * @return
520      */
521     void SetInitialUserFlag(bool flag);
522     /**
523      * @brief Get a shared pointer to the IBundleDataStorage object.
524      * @return Returns the pointer of IBundleDataStorage object.
525      */
526     std::shared_ptr<IBundleDataStorage> GetDataStorage() const;
527     /**
528      * @brief Obtains the FormInfo objects provided by all applications on the device.
529      * @param formInfos List of FormInfo objects if obtained;
530      * @return Returns true if this function is successfully called; returns false otherwise.
531      */
532     bool GetAllFormsInfo(std::vector<FormInfo> &formInfos) const;
533     /**
534      * @brief Obtains the FormInfo objects provided by a specified application on the device.
535      * @param bundleName Indicates the bundle name of the  application.
536      * @param formInfos List of FormInfo objects if obtained;
537      * @return Returns true if this function is successfully called; returns false otherwise.
538      */
539     bool GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos) const;
540     /**
541      * @brief Obtains the FormInfo objects provided by a specified module name.
542      * @param formInfos List of FormInfo objects if obtained;
543      * @param moduleName Indicates the module name of the application.
544      * @param bundleName Indicates the bundle name of the application.
545      * @return Returns true if this function is successfully called; returns false otherwise.
546      */
547     bool GetFormsInfoByModule(
548         const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos) const;
549     /**
550      * @brief Obtains the ShortcutInfo objects provided by a specified application on the device.
551      * @param bundleName Indicates the bundle name of the application.
552      * @param userId Indicates the user ID.
553      * @param shortcutInfos List of ShortcutInfo objects if obtained.
554      * @return Returns true if this function is successfully called; returns false otherwise.
555      */
556     bool GetShortcutInfos(
557         const std::string &bundleName, int32_t userId, std::vector<ShortcutInfo> &shortcutInfos) const;
558     /**
559      * @brief Obtains the ShortcutInfo objects provided by a specified application on the device.
560      * @param bundleName Indicates the bundle name of the application.
561      * @param userId Indicates the user ID.
562      * @param shortcutInfos List of ShortcutInfo objects if obtained.
563      * @return Returns errcode of the result.
564      */
565     ErrCode GetShortcutInfoV9(
566         const std::string &bundleName, int32_t userId, std::vector<ShortcutInfo> &shortcutInfos) const;
567     /**
568      * @brief Obtains the CommonEventInfo objects provided by an event key on the device.
569      * @param eventKey Indicates the event of the subscribe.
570      * @param commonEventInfos List of CommonEventInfo objects if obtained.
571      * @return Returns true if this function is successfully called; returns false otherwise.
572      */
573     bool GetAllCommonEventInfo(const std::string &eventKey, std::vector<CommonEventInfo> &commonEventInfos) const;
574     /**
575      * @brief Obtains the PreInstallBundleInfo objects provided by bundleName.
576      * @param bundleName Indicates the bundle name of the application.
577      * @param preInstallBundleInfo Indicates information about the PreInstallBundleInfo.
578      * @return Returns true if this function is successfully called; returns false otherwise.
579      */
580     bool GetPreInstallBundleInfo(const std::string &bundleName, PreInstallBundleInfo &preInstallBundleInfo);
581     /**
582      * @brief Save new PreInstallBundleInfo.
583      * @param bundleName Indicates the bundle name.
584      * @param preInstallBundleInfo Indicates the PreInstallBundleInfo object to be save.
585      * @return Returns true if this function is successfully called; returns false otherwise.
586      */
587     bool SavePreInstallBundleInfo(const std::string &bundleName, const PreInstallBundleInfo &preInstallBundleInfo);
588     /**
589      * @brief Obtains the PreInstallBundleInfo objects provided by bundleName.
590      * @param preInstallBundleInfo Indicates information about the PreInstallBundleInfo.
591      * @return Returns true if this function is successfully called; returns false otherwise.
592      */
593     bool LoadAllPreInstallBundleInfos(std::vector<PreInstallBundleInfo> &preInstallBundleInfos);
594     /**
595      * @brief Save new PreInstallBundleInfo.
596      * @param bundleName Indicates the bundle name.
597      * @param preInstallBundleInfo Indicates the PreInstallBundleInfo object to be save.
598      * @return Returns true if this function is successfully called; returns false otherwise.
599      */
600     bool DeletePreInstallBundleInfo(
601         const std::string &bundleName, const PreInstallBundleInfo &preInstallBundleInfo);
602     /**
603      * @brief Save installation mark to datebase storage.
604      * @param info Indicates the innerBundleInfo of the bundle which needs to save installation mark.
605      * @return Returns true if this function is successfully called; returns false otherwise.
606      */
607     bool SaveInnerBundleInfo(const InnerBundleInfo &info) const;
608     /**
609      * @brief GetInnerBundleUserInfoByUserId.
610      * @param bundleName Indicates the application bundle name to be queried.
611      * @param userId Indicates the user ID.
612      * @param innerBundleUserInfo Indicates the obtained InnerBundleUserInfo object.
613      * @return Returns true if the application is successfully obtained; returns false otherwise.
614      */
615     bool GetInnerBundleUserInfoByUserId(
616         const std::string &bundleName, int32_t userId, InnerBundleUserInfo &innerBundleUserInfo) const;
617     /**
618      * @brief save all created users.
619      * @param userId Indicates the user ID.
620      */
621     void AddUserId(int32_t userId);
622     /**
623      * @brief remove userId.
624      * @param userId Indicates the user ID.
625      */
626     void RemoveUserId(int32_t userId);
627     /**
628      * @brief query users.
629      * @param userId Indicates the user ID.
630      * @return Returns true when query user success; returns false otherwise.
631      */
632     bool HasUserId(int32_t userId) const;
633     /**
634      * @brief Get userId by calling uid.
635      * @return Returns userId.
636      */
637     int32_t GetUserIdByCallingUid() const;
638     /**
639      * @brief Get all user.
640      * @return Returns all userId.
641      */
642     std::set<int32_t> GetAllUser() const;
643     /**
644      * @brief Has initial user created.
645      * @return Returns initial user flag.
646      */
HasInitialUserCreated() const647     bool HasInitialUserCreated() const
648     {
649         return initialUserFlag_;
650     }
651     /**
652      * @brief Set bundlePromise.
653      * @param bundlePromise Indicates the bundlePromise.
654      */
SetBundlePromise(const std::shared_ptr<BundlePromise>& bundlePromise)655     void SetBundlePromise(const std::shared_ptr<BundlePromise>& bundlePromise)
656     {
657         bundlePromise_ = bundlePromise;
658     }
659     /**
660      * @brief Get bundleUserInfos by bundleName.
661      * @param bundleName Indicates the application bundle name to be queried.
662      * @param innerBundleUserInfo Indicates the obtained InnerBundleUserInfo object.
663      * @return Returns true if the application is successfully obtained; returns false otherwise.
664      */
665     bool GetInnerBundleUserInfos(
666         const std::string &bundleName, std::vector<InnerBundleUserInfo> &innerBundleUserInfos) const;
667     /**
668      * @brief Get app privilege level.
669      * @param bundleName Indicates the bundle name of the app privilege level.
670      * @param userId Indicates the user id.
671      * @return Returns app privilege level.
672      */
673     std::string GetAppPrivilegeLevel(
674         const std::string &bundleName, int32_t userId = Constants::UNSPECIFIED_USERID);
675     /**
676      * @brief Query a ExtensionAbilityInfo of list by the given Want.
677      * @param want Indicates the information of the ability.
678      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
679      * @param userId Indicates the user ID.
680      * @param extensionInfos Indicates the obtained ExtensionAbilityInfo of list.
681      * @return Returns true if the ExtensionAbilityInfo is successfully obtained; returns false otherwise.
682      */
683     bool QueryExtensionAbilityInfos(const Want &want, int32_t flags, int32_t userId,
684         std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
685     /**
686      * @brief Query a ExtensionAbilityInfo of list by the given Want.
687      * @param want Indicates the information of the ability.
688      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
689      * @param userId Indicates the user ID.
690      * @param extensionInfos Indicates the obtained ExtensionAbilityInfo of list.
691      * @return Returns ERR_OK if the ExtensionAbilityInfo is successfully obtained; returns errCode otherwise.
692      */
693     ErrCode QueryExtensionAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
694         std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
695 
696     /**
697      * @brief Query a ExtensionAbilityInfo without want.
698      * @param want Indicates the information of the ability.
699      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
700      * @param userId Indicates the user ID.
701      * @param extensionInfos Indicates the obtained ExtensionAbilityInfo of list.
702      * @return Returns ERR_OK if the ExtensionAbilityInfo is successfully obtained; returns errCode otherwise.
703      */
704     ErrCode QueryExtensionAbilityInfos(uint32_t flags, int32_t userId,
705         std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
706 
707     ErrCode QueryExtensionAbilityInfosByExtensionTypeName(const std::string &typeName, uint32_t flags,
708         int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
709     /**
710      * @brief Obtains the PreInstallBundleInfo objects in Cache.
711      * @return Returns PreInstallBundleInfos.
712      */
713     const std::vector<PreInstallBundleInfo> GetAllPreInstallBundleInfos();
714     /**
715      * @brief Restore uid and gid .
716      * @return Returns true if this function is successfully called; returns false otherwise.
717      */
718     bool RestoreUidAndGid();
719     /**
720      * @brief Load all bundle state data from jsonDb .
721      * @return
722      */
723     void LoadAllBundleStateDataFromJsonDb();
724 
725     bool QueryExtensionAbilityInfos(const ExtensionAbilityType &extensionType, const int32_t &userId,
726         std::vector<ExtensionAbilityInfo> &extensionInfos) const;
727 
728     bool QueryExtensionAbilityInfoByUri(const std::string &uri, int32_t userId,
729         ExtensionAbilityInfo &extensionAbilityInfo) const;
730 
731     bool AddInnerBundleUserInfo(const std::string &bundleName, const InnerBundleUserInfo& newUserInfo);
732 
733     bool RemoveInnerBundleUserInfo(const std::string &bundleName, int32_t userId);
734 
735     bool ImplicitQueryInfoByPriority(const Want &want, int32_t flags, int32_t userId,
736         AbilityInfo &abilityInfo, ExtensionAbilityInfo &extensionInfo) const;
737 
738     bool ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault,
739         std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos,
740         bool &findDefaultApp);
741     bool UpateExtResources(const std::string &bundleName,
742         const std::vector<ExtendResourceInfo> &extendResourceInfos);
743     bool RemoveExtResources(const std::string &bundleName,
744         const std::vector<std::string> &moduleNames);
745     bool UpateCurDynamicIconModule(
746         const std::string &bundleName, const std::string &moduleName);
747 
748     /**
749      * @brief Sets whether to enable isRemovable based on given bundle name, module name and isEnable.
750      * @param bundleName Indicates the bundleName.
751      * @param moduleName Indicates the moduleName.
752      * @param isEnable Set module isRemovable is enable.
753      * @return Returns true if the module isRemovable is set success; returns false otherwise.
754      */
755     bool SetModuleRemovable(const std::string &bundleName, const std::string &moduleName, bool isEnable);
756     /**
757      * @brief Get Module isRemovable by bundleName and moduleName.
758      * @param bundleName Indicates the application bundle name to be queried.
759      * @param moduleName Indicates the moduleName.
760      * @param isRemovable Indicates the module whether is removable.
761      * @return Returns ERR_OK if the module isRemovable is successfully obtained; returns other ErrCode otherwise.
762      */
763     ErrCode IsModuleRemovable(const std::string &bundleName, const std::string &moduleName, bool &isRemovable) const;
764 
765 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
766     int64_t GetBundleSpaceSize(const std::string &bundleName) const;
767     int64_t GetBundleSpaceSize(const std::string &bundleName, int32_t userId) const;
768     int64_t GetAllFreeInstallBundleSpaceSize() const;
769     bool GetFreeInstallModules(
770         std::map<std::string, std::vector<std::string>> &freeInstallModules) const;
771 #endif
772 
773     bool GetBundleStats(const std::string &bundleName,
774         const int32_t userId, std::vector<int64_t> &bundleStats, const int32_t appIndex = 0) const;
775     bool GetAllBundleStats(const int32_t userId, std::vector<int64_t> &bundleStats) const;
776     bool HasUserInstallInBundle(const std::string &bundleName, const int32_t userId) const;
777     bool GetAllDependentModuleNames(const std::string &bundleName, const std::string &moduleName,
778         std::vector<std::string> &dependentModuleNames);
779     ErrCode SetModuleUpgradeFlag(const std::string &bundleName, const std::string &moduleName, int32_t upgradeFlag);
780     int32_t GetModuleUpgradeFlag(const std::string &bundleName, const std::string &moduleName) const;
781     /**
782      * @brief Get the Inner Bundle Info With Flags object
783      * @param bundleName Indicates the application bundle name to be queried.
784      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
785      * @param info Indicates the innerBundleInfo of the bundle.
786      * @param userId Indicates the user ID.
787      * @return Returns true if get inner bundle info is successfully obtained; returns false otherwise.
788      */
789     bool GetInnerBundleInfoWithFlags(const std::string &bundleName, const int32_t flags,
790         InnerBundleInfo &info, int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) const;
791     bool GetInnerBundleInfoWithFlags(const std::string &bundleName, const int32_t flags,
792         int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) const;
793     bool GetInnerBundleInfoWithBundleFlagsAndLock(const std::string &bundleName, int32_t flags,
794         InnerBundleInfo &info, int32_t userId = Constants::UNSPECIFIED_USERID) const;
795     ErrCode GetInnerBundleInfoWithFlagsV9(const std::string &bundleName, int32_t flags,
796         InnerBundleInfo &info, int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) const;
797     ErrCode GetInnerBundleInfoWithBundleFlagsV9(const std::string &bundleName, int32_t flags,
798         InnerBundleInfo &info, int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) const;
799     std::shared_ptr<BundleSandboxAppHelper> GetSandboxAppHelper() const;
800 
801 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
802     bool QueryInfoAndSkillsByElement(int32_t userId, const Element& element,
803         AbilityInfo& abilityInfo, ExtensionAbilityInfo& extensionInfo, std::vector<Skill>& skills) const;
804 
805     bool GetElement(int32_t userId, const ElementName& elementName, Element& element) const;
806 #endif
807 
808     int32_t GetUserId(int32_t userId = Constants::UNSPECIFIED_USERID) const;
809 
810     ErrCode GetMediaData(const std::string &bundleName, const std::string &moduleName, const std::string &abilityName,
811         std::unique_ptr<uint8_t[]> &mediaDataPtr, size_t &len, int32_t userId) const;
812 
813     std::shared_mutex &GetStatusCallbackMutex();
814 
815     std::vector<sptr<IBundleStatusCallback>> GetCallBackList() const;
816 
817     std::string GetStringById(const std::string &bundleName, const std::string &moduleName,
818         uint32_t resId, int32_t userId, const std::string &localeInfo);
819 
820     std::string GetIconById(
821         const std::string &bundleName, const std::string &moduleName, uint32_t resId, uint32_t density, int32_t userId);
822     void UpdateRemovable(const std::string &bundleName, bool removable);
823     void UpdatePrivilegeCapability(
824         const std::string &bundleName, const ApplicationInfo &appInfo);
825     bool FetchInnerBundleInfo(
826         const std::string &bundleName, InnerBundleInfo &innerBundleInfo);
827     bool GetInnerBundleInfoUsers(const std::string &bundleName, std::set<int32_t> &userIds);
828     bool IsSystemHsp(const std::string &bundleName);
829 
830     bool UpdateUninstallBundleInfo(const std::string &bundleName, const UninstallBundleInfo &uninstallBundleInfo);
831     bool GetUninstallBundleInfo(const std::string &bundleName, UninstallBundleInfo &uninstallBundleInfo);
832     bool DeleteUninstallBundleInfo(const std::string &bundleName, int32_t userId);
833 
834     bool UpdateQuickFixInnerBundleInfo(const std::string &bundleName, const InnerBundleInfo &innerBundleInfo);
835 
836     void NotifyBundleEventCallback(const EventFwk::CommonEventData &eventData) const;
837 
GetAllInnerBundleInfos() const838     const std::map<std::string, InnerBundleInfo> GetAllInnerBundleInfos() const
839     {
840         std::shared_lock<std::shared_mutex> lock(bundleInfoMutex_);
841         return bundleInfos_;
842     }
843 
844     bool QueryOverlayInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info);
845 
846     void SaveOverlayInfo(const std::string &bundleName, InnerBundleInfo &innerBundleInfo);
847 
848     ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId,
849         AppProvisionInfo &appProvisionInfo);
850 
851     virtual ErrCode GetProvisionMetadata(const std::string &bundleName, int32_t userId,
852         std::vector<Metadata> &provisionMetadatas) const;
853 
854     ErrCode GetBaseSharedBundleInfos(const std::string &bundleName,
855         std::vector<BaseSharedBundleInfo> &baseSharedBundleInfos,
856         GetDependentBundleInfoFlag flag = GetDependentBundleInfoFlag::GET_APP_CROSS_HSP_BUNDLE_INFO) const;
857 
858     bool GetBaseSharedBundleInfo(const Dependency &dependency, BaseSharedBundleInfo &baseSharedBundleInfo) const;
859 
860     ErrCode GetAllSharedBundleInfo(std::vector<SharedBundleInfo> &sharedBundles) const;
861 
862     ErrCode GetSharedBundleInfo(const std::string &bundleName, const std::string &moduleName,
863         std::vector<SharedBundleInfo> &sharedBundles);
864 
865     bool DeleteSharedBundleInfo(const std::string &bundleName);
866 
867     ErrCode GetSharedBundleInfoBySelf(const std::string &bundleName, SharedBundleInfo &sharedBundleInfo);
868 
869     ErrCode GetSharedDependencies(const std::string &bundleName, const std::string &moduleName,
870         std::vector<Dependency> &dependencies);
871 
872     bool CheckHspVersionIsRelied(int32_t versionCode, const InnerBundleInfo &info) const;
873     bool CheckHspBundleIsRelied(const std::string &hspBundleName) const;
874     bool IsPreInstallApp(const std::string &bundleName);
875     bool GetBundleType(const std::string &bundleName, BundleType &bundleType)const;
876 
877     ErrCode GetSharedBundleInfo(const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo);
878     ErrCode GetSpecifiedDistributionType(const std::string &bundleName, std::string &specifiedDistributionType);
879     ErrCode GetAdditionalInfo(const std::string &bundleName, std::string &additionalInfo);
880 
881     ErrCode GetProxyDataInfos(const std::string &bundleName, const std::string &moduleName, int32_t userId,
882         std::vector<ProxyData> &proxyDatas) const;
883 
884     ErrCode GetAllProxyDataInfos(int32_t userId, std::vector<ProxyData> &proxyDatas) const;
885 
886     std::string GetBundleNameByAppId(const std::string &appId) const;
887 
888     void SetAOTCompileStatus(const std::string &bundleName, const std::string &moduleName,
889         AOTCompileStatus aotCompileStatus, uint32_t versionCode);
890     void ResetAOTFlags();
891     void ResetAOTFlagsCommand(const std::string &bundleName);
892     ErrCode ResetAOTCompileStatus(const std::string &bundleName, const std::string &moduleName,
893         int32_t triggerMode);
894     std::vector<std::string> GetAllBundleName() const;
895     std::vector<std::string> GetAllDriverBundleName() const;
896     bool IsBundleExist(const std::string &bundleName) const;
897     bool QueryInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info) const;
898     std::vector<int32_t> GetUserIds(const std::string &bundleName) const;
899     ErrCode SetExtNameOrMIMEToApp(const std::string &bundleName, const std::string &moduleName,
900         const std::string &abilityName, const std::string &extName, const std::string &mimeType);
901     ErrCode DelExtNameOrMIMEToApp(const std::string &bundleName, const std::string &moduleName,
902         const std::string &abilityName, const std::string &extName, const std::string &mimeType);
903     bool QueryAppGalleryAbilityName(std::string &bundleName, std::string &abilityName);
904     bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::vector<DataGroupInfo> &infos) const;
905     bool GetGroupDir(const std::string &dataGroupId, std::string &dir,
906         int32_t userId = Constants::UNSPECIFIED_USERID) const;
907     void GenerateDataGroupUuidAndUid(DataGroupInfo &dataGroupInfo, int32_t userId,
908         std::map<std::string, std::pair<int32_t, std::string>> &dataGroupIndexMap) const;
909     void GenerateDataGroupInfos(InnerBundleInfo &innerBundleInfo,
910         const std::vector<std::string> &dataGroupIdList, int32_t userId) const;
911     void GetDataGroupIndexMap(std::map<std::string, std::pair<int32_t, std::string>> &dataGroupIndexMap) const;
912     bool IsShareDataGroupId(const std::string &dataGroupId, int32_t userId) const;
913     ErrCode GetJsonProfile(ProfileType profileType, const std::string &bundleName, const std::string &moduleName,
914         std::string &profile, int32_t userId) const;
915     ErrCode GetJsonProfileByExtractor(const std::string &hapPath, const std::string &profilePath,
916         std::string &profile) const;
917     bool GetOldAppIds(const std::string &bundleName, std::vector<std::string> &appIds) const;
918     ErrCode GetInnerBundleInfoByUid(const int32_t uid, InnerBundleInfo &innerBundleInfo) const;
919     ErrCode GetInnerBundleInfoAndIndexByUid(const int32_t uid, InnerBundleInfo &innerBundleInfo,
920         int32_t &appIndex) const;
921     std::string GetModuleNameByBundleAndAbility(const std::string& bundleName, const std::string& abilityName);
922     const std::vector<PreInstallBundleInfo> GetRecoverablePreInstallBundleInfos();
923     ErrCode SetAdditionalInfo(const std::string& bundleName, const std::string& additionalInfo) const;
924     ErrCode GetAppServiceHspBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo);
925     ErrCode CreateBundleDataDir(int32_t userId);
926     void GenerateOdid(const std::string &developerId, std::string &odid) const;
927     ErrCode GetOdid(std::string &odid) const;
928     ErrCode GetOdidByBundleName(const std::string &bundleName, std::string &odid) const;
929     void UpdateRouterInfo(const std::string &bundleName);
930     bool DeleteRouterInfo(const std::string &bundleName);
931     bool DeleteRouterInfo(const std::string &bundleName, const std::string &moduleName);
932     void GetAllBundleNames(std::set<std::string> &bundleNames);
933 
934     void UpdateIsPreInstallApp(const std::string &bundleName, bool isPreInstallApp);
935 
936     /**
937      * @brief Check whether the link can be opened.
938      * @param link Indicates the link to be opened.
939      * @param canOpen Indicates whether the link can be opened.
940      * @return  Returns result of the operation.
941      */
942     ErrCode CanOpenLink(
943         const std::string &link, bool &canOpen) const;
944     ErrCode GetAllBundleInfoByDeveloperId(const std::string &developerId,
945         std::vector<BundleInfo> &bundleInfos, int32_t userId);
946     ErrCode GetDeveloperIds(const std::string &appDistributionType,
947         std::vector<std::string> &developerIdList, int32_t userId);
948     ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state, const bool isNeedSendNotify);
949 
950     ErrCode AddCloneBundle(const std::string &bundleName, const InnerBundleCloneInfo &attr);
951     ErrCode RemoveCloneBundle(const std::string &bundleName, const int32_t userId, int32_t appIndex);
952     ErrCode QueryAbilityInfoByContinueType(const std::string &bundleName, const std::string &continueType,
953         AbilityInfo &abilityInfo, int32_t userId, int32_t appIndex = 0) const;
954     ErrCode GetBundleNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex) const;
955 
956     ErrCode QueryCloneAbilityInfo(const ElementName &element, int32_t flags, int32_t userId,
957         int32_t appIndex, AbilityInfo &abilityInfo) const;
958     ErrCode GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appIndex,
959         BundleInfo &bundleInfo, int32_t userId) const;
960     std::vector<int32_t> GetCloneAppIndexes(const std::string &bundleName, int32_t userId) const;
961 
962     ErrCode ExplicitQueryExtensionInfoV9(const Want &want, int32_t flags, int32_t userId,
963         ExtensionAbilityInfo &extensionInfo, int32_t appIndex = 0) const;
964 
965     void QueryAllCloneExtensionInfos(const Want &want, int32_t flags, int32_t userId,
966         std::vector<ExtensionAbilityInfo> &infos) const;
967     void QueryAllCloneExtensionInfosV9(const Want &want, int32_t flags, int32_t userId,
968         std::vector<ExtensionAbilityInfo> &infos) const;
969 
970     ErrCode GetAppIdByBundleName(const std::string &bundleName, std::string &appId) const;
971 
972     ErrCode GetSignatureInfoByBundleName(const std::string &bundleName, SignatureInfo &signatureInfo) const;
973 
974     ErrCode UpdateAppEncryptedStatus(const std::string &bundleName, bool isExisted, int32_t appIndex = 0);
975 
976     ErrCode AddDesktopShortcutInfo(const ShortcutInfo &shortcutInfo, int32_t userId);
977     ErrCode DeleteDesktopShortcutInfo(const ShortcutInfo &shortcutInfo, int32_t userId);
978     ErrCode GetAllDesktopShortcutInfo(int32_t userId, std::vector<ShortcutInfo> &shortcutInfos);
979     ErrCode DeleteDesktopShortcutInfo(const std::string &bundleName);
980     ErrCode DeleteDesktopShortcutInfo(const std::string &bundleName, int32_t userId, int32_t appIndex);
981 
982     void GetBundleInfosForContinuation(std::vector<BundleInfo> &bundleInfos) const;
983 
984     /**
985      * @brief Get a list of application package names that continue the specified package name.
986      * @param continueBundleName The package name that is being continued.
987      * @param bundleNames Continue the list of specified package names.
988      * @param userId Indicates the user ID.
989      * @return Returns ERR_OK if successfully obtained; returns error code otherwise.
990      */
991     ErrCode GetContinueBundleNames(
992         const std::string &continueBundleName, std::vector<std::string> &bundleNames, int32_t userId);
993 
994     ErrCode IsBundleInstalled(const std::string &bundleName, int32_t userId, int32_t appIndex, bool &isInstalled);
995     void CreateEl5Dir(const std::vector<CreateDirParam> &el5Params);
996 
997 private:
998     /**
999      * @brief Init transferStates.
1000      * @return
1001      */
1002     void InitStateTransferMap();
1003     /**
1004      * @brief Determine whether to delete the data status.
1005      * @param state Indicates the InstallState object.
1006      * @return Returns true if state is INSTALL_FAIL,UNINSTALL_FAIL,UNINSTALL_SUCCESS,or UPDATING_FAIL; returns false
1007      * otherwise.
1008      */
1009     bool IsDeleteDataState(const InstallState state) const;
1010     /**
1011      * @brief Determine whether it is disable.
1012      * @param state Indicates the InstallState object.
1013      * @return Returns true if install state is UPDATING_START or UNINSTALL_START; returns false otherwise.
1014      */
1015     bool IsDisableState(const InstallState state) const;
1016     /**
1017      * @brief Delete bundle info if InstallState is not INSTALL_FAIL.
1018      * @param bundleName Indicates the bundle Names.
1019      * @param state Indicates the InstallState object.
1020      * @return Returns true if install state is UPDATING_START or UNINSTALL_START; returns false otherwise.
1021      */
1022     void DeleteBundleInfo(const std::string &bundleName, const InstallState state);
1023     /**
1024      * @brief Implicit query abilityInfos by the given Want.
1025      * @param want Indicates the information of the ability.
1026      * @param flags Indicates the information contained in the AbilityInfo object to be returned.
1027      * @param userId Indicates the user ID.
1028      * @param abilityInfos Indicates the obtained AbilityInfo of list.
1029      * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise.
1030      */
1031     bool ImplicitQueryAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1032         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex = 0) const;
1033     ErrCode ImplicitQueryAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1034         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex = 0) const;
1035     bool CheckAbilityInfoFlagExist(int32_t flags, AbilityInfoFlag abilityInfoFlag) const;
1036     void GetMatchAbilityInfos(const Want &want, int32_t flags, const InnerBundleInfo &info,
1037         int32_t userId, std::vector<AbilityInfo> &abilityInfos,
1038         const std::vector<std::string> &paramMimeTypes, int32_t appIndex = 0) const;
1039     void AddSkillUrisInfo(const std::vector<Skill> &skills, std::vector<SkillUriForAbilityAndExtension> &skillUris,
1040         std::optional<size_t> matchSkillIndex, std::optional<size_t> matchUriIndex) const;
1041     void GetMatchAbilityInfosV9(const Want &want, int32_t flags, const InnerBundleInfo &info,
1042         int32_t userId, std::vector<AbilityInfo> &abilityInfos,
1043         const std::vector<std::string> &paramMimeTypes, int32_t appIndex = 0) const;
1044     bool ExplicitQueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo,
1045         int32_t appIndex = 0) const;
1046     ErrCode ExplicitQueryAbilityInfoV9(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo,
1047         int32_t appIndex = 0) const;
1048     bool GenerateBundleId(const std::string &bundleName, int32_t &bundleId);
1049     int32_t GetUserIdByUid(int32_t uid) const;
1050     bool GetAllBundleInfos(int32_t flags, std::vector<BundleInfo> &bundleInfos) const;
1051     ErrCode GetAllBundleInfosV9(int32_t flags, std::vector<BundleInfo> &bundleInfos) const;
1052     bool ExplicitQueryExtensionInfo(const Want &want, int32_t flags, int32_t userId,
1053         ExtensionAbilityInfo &extensionInfo, int32_t appIndex = 0) const;
1054     bool ImplicitQueryExtensionInfos(const Want &want, int32_t flags, int32_t userId,
1055         std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
1056     ErrCode ImplicitQueryExtensionInfosV9(const Want &want, int32_t flags, int32_t userId,
1057         std::vector<ExtensionAbilityInfo> &extensionInfos, int32_t appIndex = 0) const;
1058     void GetMatchExtensionInfos(const Want &want, int32_t flags, const int32_t &userId, const InnerBundleInfo &info,
1059         std::vector<ExtensionAbilityInfo> &einfos, int32_t appIndex = 0) const;
1060     void GetMatchExtensionInfosV9(const Want &want, int32_t flags, int32_t userId, const InnerBundleInfo &info,
1061         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex = 0) const;
1062     void GetAllExtensionInfos(uint32_t flags, int32_t userId, const InnerBundleInfo &info,
1063         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex = 0) const;
1064     void GetAllExtensionInfosByExtensionTypeName(const std::string &typeName, uint32_t flags, int32_t userId,
1065         const InnerBundleInfo &info, std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex = 0) const;
1066     bool MatchUtd(const Skill &skill, const std::string &utd, int32_t count) const;
1067     bool MatchUtd(const std::string &skillUtd, const std::string &wantUtd) const;
1068     bool MatchTypeWithUtd(const std::string &mimeType, const std::string &wantUtd) const;
1069     std::vector<int32_t> GetCloneAppIndexesNoLock(const std::string &bundleName, int32_t userId) const;
1070     void GetCloneAppInfo(const InnerBundleInfo &info, int32_t userId, int32_t flags,
1071         std::vector<ApplicationInfo> &appInfos) const;
1072     void GetCloneAppInfoV9(const InnerBundleInfo &info, int32_t userId, int32_t flags,
1073         std::vector<ApplicationInfo> &appInfos) const;
1074 #ifdef GLOBAL_RESMGR_ENABLE
1075     std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager(const std::string &bundleName,
1076         const std::string &moduleName, int32_t userId, const std::string &localeInfo = Constants::EMPTY_STRING) const;
1077 #endif
1078 
1079     void FilterAbilityInfosByModuleName(const std::string &moduleName, std::vector<AbilityInfo> &abilityInfos) const;
1080     void CreateGroupDir(const InnerBundleInfo &innerBundleInfo, int32_t userId) const;
1081     void InnerCreateEl5Dir(const CreateDirParam &el5Param);
1082     void SetEl5DirPolicy(const CreateDirParam &el5Param);
1083 
1084     void FilterExtensionAbilityInfosByModuleName(const std::string &moduleName,
1085         std::vector<ExtensionAbilityInfo> &extensionInfos) const;
1086     void CompatibleOldBundleStateInKvDb();
1087     void ResetBundleStateData();
1088     bool QueryAbilityInfoWithFlags(const std::optional<AbilityInfo> &option, int32_t flags, int32_t userId,
1089         const InnerBundleInfo &innerBundleInfo, AbilityInfo &info, int32_t appIndex = 0) const;
1090     ErrCode QueryAbilityInfoWithFlagsV9(const std::optional<AbilityInfo> &option, int32_t flags, int32_t userId,
1091         const InnerBundleInfo &innerBundleInfo, AbilityInfo &info,
1092         int32_t appIndex = 0) const;
1093     bool ImplicitQueryCurAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1094         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex) const;
1095     ErrCode ImplicitQueryCurAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1096         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex) const;
1097     void ImplicitQueryAllAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1098         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex) const;
1099     void ImplicitQueryAllAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1100         std::vector<AbilityInfo> &abilityInfos, int32_t appIndex) const;
1101     bool ImplicitQueryCurExtensionInfos(const Want &want, int32_t flags, int32_t userId,
1102         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex) const;
1103     ErrCode ImplicitQueryCurExtensionInfosV9(const Want &want, int32_t flags, int32_t userId,
1104         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex) const;
1105     void ImplicitQueryAllExtensionInfos(const Want &want, int32_t flags, int32_t userId,
1106         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex) const;
1107     void ImplicitQueryAllExtensionInfosV9(const Want &want, int32_t flags, int32_t userId,
1108         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex) const;
1109     ErrCode ImplicitQueryAllExtensionInfos(uint32_t flags, int32_t userId,
1110         std::vector<ExtensionAbilityInfo> &infos, int32_t appIndex, const std::string &typeName = "") const;
1111     void GetMatchLauncherAbilityInfosForCloneInfos(const InnerBundleInfo& info, const AbilityInfo &abilityInfo,
1112         const InnerBundleUserInfo &bundleUserInfo, std::vector<AbilityInfo>& abilityInfos) const;
1113     void ModifyApplicationInfoByCloneInfo(const InnerBundleCloneInfo &cloneInfo,
1114         ApplicationInfo &applicationInfo) const;
1115     void ModifyBundleInfoByCloneInfo(const InnerBundleCloneInfo &cloneInfo, BundleInfo &bundleInfo) const;
1116     void GetCloneBundleInfos(const InnerBundleInfo& info, int32_t flags, int32_t userId,
1117         BundleInfo &bundleInfo, std::vector<BundleInfo> &bundleInfos) const;
1118     void GetBundleNameAndIndexByName(const std::string &keyName, std::string &bundleName, int32_t &appIndex) const;
1119     void GetCloneAbilityInfos(std::vector<AbilityInfo> &abilityInfos,
1120         const ElementName &element, int32_t flags, int32_t userId) const;
1121     void GetCloneAbilityInfosV9(std::vector<AbilityInfo> &abilityInfos,
1122         const ElementName &element, int32_t flags, int32_t userId) const;
1123     ErrCode ExplicitQueryCloneAbilityInfo(const ElementName &element, int32_t flags, int32_t userId,
1124         int32_t appIndex, AbilityInfo &abilityInfo) const;
1125     ErrCode ExplicitQueryCloneAbilityInfoV9(const ElementName &element, int32_t flags, int32_t userId,
1126         int32_t appIndex, AbilityInfo &abilityInfo) const;
1127     void ImplicitQueryCloneAbilityInfos(
1128         const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
1129     bool ImplicitQueryCurCloneAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1130         std::vector<AbilityInfo> &abilityInfos) const;
1131     void ImplicitQueryAllCloneAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1132         std::vector<AbilityInfo> &abilityInfos) const;
1133     void ImplicitQueryCloneAbilityInfosV9(
1134         const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) const;
1135     bool ImplicitQueryCurCloneAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1136         std::vector<AbilityInfo> &abilityInfos) const;
1137     void ImplicitQueryAllCloneAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1138         std::vector<AbilityInfo> &abilityInfos) const;
1139     bool ImplicitQueryCurCloneExtensionAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1140         std::vector<ExtensionAbilityInfo> &abilityInfos) const;
1141     ErrCode ImplicitQueryCurCloneExtensionAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1142         std::vector<ExtensionAbilityInfo> &abilityInfos) const;
1143     bool ImplicitQueryAllCloneExtensionAbilityInfos(const Want &want, int32_t flags, int32_t userId,
1144         std::vector<ExtensionAbilityInfo> &infos) const;
1145     ErrCode ImplicitQueryAllCloneExtensionAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
1146         std::vector<ExtensionAbilityInfo> &abilityInfos) const;
1147     ErrCode CheckInnerBundleInfoWithFlags(
1148         const InnerBundleInfo &innerBundleInfo, const int32_t flags, int32_t userId, int32_t appIndex = 0) const;
1149     ErrCode CheckInnerBundleInfoWithFlagsV9(
1150         const InnerBundleInfo &innerBundleInfo, const int32_t flags, int32_t userId, int32_t appIndex = 0) const;
1151     void AddAppDetailAbilityInfo(InnerBundleInfo &info) const;
1152     void GetAllLauncherAbility(const Want &want, std::vector<AbilityInfo> &abilityInfos,
1153         const int32_t userId, const int32_t requestUserId) const;
1154     ErrCode GetLauncherAbilityByBundleName(const Want &want, std::vector<AbilityInfo> &abilityInfos,
1155         const int32_t userId, const int32_t requestUserId) const;
1156     void ModifyLauncherAbilityInfo(bool isStage, AbilityInfo &abilityInfo) const;
1157     bool MatchPrivateType(const Want &want, const std::vector<std::string> &supportExtNames,
1158         const std::vector<std::string> &supportMimeTypes, const std::vector<std::string> &paramMimeTypes) const;
1159     bool UpdateOverlayInfo(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo);
1160     void ResetExternalOverlayModuleState(const std::string &bundleName, const std::string &modulePackage);
1161     void BuildExternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId);
1162     void RemoveOverlayInfoAndConnection(const InnerBundleInfo &innerBundleInfo, const std::string &bundleName);
1163     ErrCode FindAbilityInfoInBundleInfo(const InnerBundleInfo &innerBundleInfo, const std::string &moduleName,
1164         const std::string &abilityName, AbilityInfo &abilityInfo) const;
1165     void RestoreSandboxUidAndGid(std::map<int32_t, std::string> &bundleIdMap);
1166     bool IsUpdateInnerBundleInfoSatisified(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const;
1167     ErrCode ProcessBundleMenu(BundleInfo& bundleInfo, int32_t flag, bool clearData) const;
1168     bool MatchShare(const Want &want, const std::vector<Skill> &skills) const;
1169     std::vector<Skill> FindSkillsContainShareAction(const std::vector<Skill> &skills) const;
1170     void EmplaceExtensionInfo(const InnerBundleInfo &info, const std::vector<Skill> &skills,
1171         ExtensionAbilityInfo &extensionInfo, int32_t flags, int32_t userId, std::vector<ExtensionAbilityInfo> &infos,
1172         std::optional<size_t> matchSkillIndex, std::optional<size_t> matchUriIndex, int32_t appIndex = 0) const;
1173     void EmplaceAbilityInfo(const InnerBundleInfo &info, const std::vector<Skill> &skills, AbilityInfo &abilityInfo,
1174         int32_t flags, int32_t userId, std::vector<AbilityInfo> &infos,
1175         std::optional<size_t> matchSkillIndex, std::optional<size_t> matchUriIndex, int32_t appIndex = 0) const;
1176     void AddAppHspBundleName(const BundleType type, const std::string &bundleName);
1177     void ConvertServiceHspToSharedBundleInfo(const InnerBundleInfo &innerBundleInfo,
1178         std::vector<BaseSharedBundleInfo> &baseSharedBundleInfos) const;
1179     void ProcessBundleRouterMap(BundleInfo& bundleInfo, int32_t flag) const;
1180     void ProcessAllowedAcls(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo) const;
1181     void FilterAbilityInfosByAppLinking(const Want &want, int32_t flags,
1182         std::vector<AbilityInfo> &abilityInfos) const;
1183     void GetMultiLauncherAbilityInfo(const Want& want,
1184         const InnerBundleInfo& info, const InnerBundleUserInfo &bundleUserInfo,
1185         int64_t installTime, std::vector<AbilityInfo>& abilityInfos) const;
1186 
1187     void PreProcessAnyUserFlag(const std::string &bundleName, int32_t& flags, int32_t &userId) const;
1188     void PostProcessAnyUserFlags(int32_t flags, int32_t userId,
1189         int32_t originalUserId, BundleInfo &bundleInfo) const;
1190     void GetExtensionAbilityInfoByTypeName(uint32_t flags, int32_t userId,
1191         std::vector<ExtensionAbilityInfo> &infos, const std::string &typeName) const;
1192     bool GetShortcutInfosByInnerBundleInfo(
1193         const InnerBundleInfo &info, std::vector<ShortcutInfo> &shortcutInfos) const;
1194 private:
1195     mutable std::shared_mutex bundleInfoMutex_;
1196     mutable std::mutex stateMutex_;
1197     mutable std::shared_mutex bundleIdMapMutex_;
1198     mutable std::shared_mutex callbackMutex_;
1199     mutable ffrt::mutex eventCallbackMutex_;
1200     mutable std::shared_mutex bundleMutex_;
1201     mutable std::mutex multiUserIdSetMutex_;
1202     bool initialUserFlag_ = false;
1203     int32_t baseAppUid_ = Constants::BASE_APP_UID;
1204     // using for locking by bundleName
1205     std::unordered_map<std::string, std::mutex> bundleMutexMap_;
1206     // using for generating bundleId
1207     // key:bundleId
1208     // value:bundleName
1209     std::map<int32_t, std::string> bundleIdMap_;
1210     // save all created users.
1211     std::set<int32_t> multiUserIdsSet_;
1212     // use vector because these functions using for IPC, the bundleName may duplicate
1213     std::vector<sptr<IBundleStatusCallback>> callbackList_;
1214     // common event callback
1215     std::vector<sptr<IBundleEventCallback>> eventCallbackList_;
1216     // all installed bundles
1217     // key:bundleName
1218     // value:innerbundleInfo
1219     std::map<std::string, InnerBundleInfo> bundleInfos_;
1220     // key:bundle name
1221     std::map<std::string, InstallState> installStates_;
1222     // current-status:previous-statue pair
1223     std::multimap<InstallState, InstallState> transferStates_;
1224     std::shared_ptr<IBundleDataStorage> dataStorage_;
1225     std::shared_ptr<IPreInstallDataStorage> preInstallDataStorage_;
1226     std::shared_ptr<BundleStateStorage> bundleStateStorage_;
1227     std::shared_ptr<BundlePromise> bundlePromise_ = nullptr;
1228     std::shared_ptr<BundleSandboxAppHelper> sandboxAppHelper_;
1229     mutable std::mutex hspBundleNameMutex_;
1230     std::set<std::string> appServiceHspBundleName_;
1231     std::shared_ptr<IShortcutDataStorage> shortcutStorage_;
1232     std::shared_ptr<IRouterDataStorage> routerStorage_;
1233     std::shared_ptr<UninstallDataMgrStorageRdb> uninstallDataMgr_;
1234 };
1235 }  // namespace AppExecFwk
1236 }  // namespace OHOS
1237 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_MGR_H
1238