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