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