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