• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_MGR_SERVICE_EVENT_HANDLER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_EVENT_HANDLER_H
18 
19 #include <list>
20 #include <map>
21 #include <unordered_set>
22 
23 #include "bundle_constants.h"
24 #include "bundle_data_mgr.h"
25 #include "bundle_mgr_host_impl.h"
26 #include "bundle_verify_mgr.h"
27 #include "common_event_manager.h"
28 #include "common_event_subscriber.h"
29 #include "common_event_support.h"
30 #include "pre_install_bundle_info.h"
31 #include "pre_install_exception_mgr.h"
32 #include "pre_scan_info.h"
33 #include "nlohmann/json.hpp"
34 
35 namespace OHOS {
36 namespace AppExecFwk {
37 class BundleMgrService;
38 enum class ScanMode : uint8_t;
39 enum class ResultMode : uint8_t;
40 
41 enum class ResultCode : uint8_t {
42     RECOVER_OK = 0,
43     REINSTALL_OK,
44     NO_INSTALLED_DATA,
45     SYSTEM_ERROR,
46 };
47 
48 enum OTAFlag : uint32_t {
49     CHECK_ELDIR = 0x00000001,
50     CHECK_LOG_DIR = 0x00000010,
51     CHECK_FILE_MANAGER_DIR = 0x00000100,
52     CHECK_SHADER_CAHCE_DIR = 0x00000200,
53     CHECK_PREINSTALL_DATA = 0x00000400,
54     CHECK_CLOUD_SHADER_DIR = 0x00000800,
55     CHECK_BACK_UP_DIR = 0x00001000,
56     CHECK_RECOVERABLE_APPLICATION_INFO = 0x00002000,
57     CHECK_INSTALL_SOURCE = 0x00004000,
58     DELETE_DEPRECATED_ARK_PATHS = 0x00008000,
59     CHECK_EXTENSION_ABILITY = 0x00010000,
60     PROCESS_DYNAMIC_ICON = 0x00020000,
61     PROCESS_THEME_AND_DYNAMIC_ICON = 0x00040000,
62     CHECK_SYSTEM_OPTIMIZE_SHADER_CAHCE_DIR = 0x00080000,
63 };
64 
65 enum class ScanResultCode : uint8_t {
66     SCAN_HAS_DATA_PARSE_SUCCESS,
67     SCAN_HAS_DATA_PARSE_FAILED,
68     SCAN_NO_DATA,
69 };
70 
71 enum class ModuleUpdateStatus : uint8_t {
72     DEFAULT = 1,
73     UPDATE = 2,
74     REVERT = 3
75 };
76 
77 struct HmpBundlePathInfo {
78     std::string bundleName;
79     std::string hmpName;
80     std::string bundleDir;
81     std::string hspDir;
82 };
83 
84 class BMSEventHandler {
85 public:
86     BMSEventHandler();
87     ~BMSEventHandler();
88     /**
89      * @brief Get preInstall root dir list,
90      *        which the catalog of production has higher priority.
91      * @param rootDirList Indicates the root dir list.
92      * @return
93      */
94     static void GetPreInstallRootDirList(std::vector<std::string> &rootDirList);
95     /**
96      * @brief Load all preInstall infos from proFile.
97      * @return Returns true if get the preInstall list successfully; returns false otherwise.
98      */
99     static bool LoadPreInstallProFile();
100     /**
101      * @brief Clear all preInstall infos cache.
102      * @return
103      */
104     static void ClearPreInstallCache();
105     /**
106      * @brief Get the preInstall capability.
107      * @param preBundleConfigInfo Indicates the preBundleConfigInfo.
108      * @return Returns true if get the preInstall capability successfully; returns false otherwise.
109      */
110     static bool GetPreInstallCapability(PreBundleConfigInfo &preBundleConfigInfo);
111     /**
112      * @brief Check extension type name in the configuration file.
113      * @param extensionTypeName Indicates the extensionTypeName to check in the configuration file.
114      * @return Returns true if the extensionTypeName is in the configuration file; returns false otherwise.
115      */
116     static bool CheckExtensionTypeInConfig(const std::string &extensionTypeName);
117     /**
118      * @brief Has preInstall profile or not.
119      * @return Returns result.
120      */
121     static bool HasPreInstallProfile();
122     /**
123      * @brief Bms start event.
124      * @return
125      */
126     void BmsStartEvent();
127 
128     static void ProcessRebootQuickFixBundleInstall(const std::string &path, bool isOta);
129 
130     static void ProcessRebootQuickFixUnInstallAndRecover(const std::string &path);
131 
132     static void SavePreInstallException(const std::string &bundleDir);
133 
134     static void ProcessSystemBundleInstall(
135         const PreScanInfo &preScanInfo,
136         Constants::AppType appType,
137         int32_t userId = Constants::UNSPECIFIED_USERID);
138 
139     static bool CheckOtaFlag(OTAFlag flag, bool &result);
140 
141     static bool UpdateOtaFlag(OTAFlag flag);
142 
143     static bool SaveBmsSystemTimeForShortcut();
144 private:
145     /**
146      * @brief Before Bms start.
147      * @return
148      */
149     void BeforeBmsStart();
150     /**
151      * @brief On Bms starting.
152      * @return
153      */
154     void OnBmsStarting();
155     /**
156      * @brief After Bms start.
157      * @return
158      */
159     void AfterBmsStart();
160     /**
161      * @brief Load install infos from db.
162      * @return Returns true if load successfully; returns false otherwise.
163      */
164     bool LoadInstallInfosFromDb();
165     /**
166      * @brief Guard against install infos lossed strategy.
167      * @return Returns ResultCode for recover install infos.
168      */
169     ResultCode GuardAgainstInstallInfosLossedStrategy();
170     /**
171      * @brief Scan and analyze install infos.
172      * @param installInfos Indicates the install infos.
173      * @return
174      */
175     void ScanAndAnalyzeInstallInfos(
176         std::map<std::string, std::vector<InnerBundleInfo>> &installInfos);
177     /**
178      * @brief Scan and analyze common install dir.
179      * @param installInfos Indicates the install infos.
180      * @return
181      */
182     void ScanInstallDir(
183         std::map<std::string, std::vector<std::string>> &hapPathsMap);
184     /**
185      * @brief Get preInstall haps.
186      * @param bundleDirs Indicates preInstall hapPath.
187      * @return
188      */
189     void GetPreInstallDir(std::vector<std::string> &bundleDirs);
190     /**
191      * @brief Analyze hap to InnerBundleInfo.
192      * @param isPreInstallApp Indicates is preInstallApp or not.
193      * @param hapPathsMap Indicates the hapPathsMap which will be analyzed.
194      * @param installInfos Indicates the install infos.
195      * @return
196      */
197     void AnalyzeHaps(
198         bool isPreInstallApp,
199         const std::map<std::string, std::vector<std::string>> &hapPathsMap,
200         std::map<std::string, std::vector<InnerBundleInfo>> &installInfos);
201     /**
202      * @brief Analyze hap to InnerBundleInfo.
203      * @param isPreInstallApp Indicates is preInstallApp or not.
204      * @param bundleDirs Indicates the bundleDirs which will be analyzed.
205      * @param installInfos Indicates the install infos.
206      * @return
207      */
208     void AnalyzeHaps(
209         bool isPreInstallApp,
210         const std::vector<std::string> &bundleDirs,
211         std::map<std::string, std::vector<InnerBundleInfo>> &installInfos);
212     /**
213      * @brief Get preBundle install dir.
214      * @param bundleDirs Indicates the bundleDirs.
215      * @return
216      */
217     void GetPreBundleDir(std::list<std::string> &bundleDirs);
218     /**
219      * @brief Check scaned hapPath whether end with .hap.
220      * @param hapPaths Indicates the hapPaths.
221      * @return Returns the checked hapPaths.
222      */
223     std::vector<std::string> CheckHapPaths(const std::vector<std::string> &hapPaths);
224     /**
225      * @brief Collect install infos from parse result.
226      * @param hapInfos Indicates the parse result.
227      * @param installInfos Indicates the saved installInfos.
228      * @return.
229      */
230     void CollectInstallInfos(
231         const std::unordered_map<std::string, InnerBundleInfo> &hapInfos,
232         std::map<std::string, std::vector<InnerBundleInfo>> &installInfos);
233     /**
234      * @brief Scan and analyze userDatas.
235      * @param userMaps Indicates the userMaps to save userInfo.
236      * @return Returns ScanResultCode if Scan and analyze infos successfully; returns false otherwise.
237      */
238     ScanResultCode ScanAndAnalyzeUserDatas(
239         std::map<std::string, std::vector<InnerBundleUserInfo>> &userMaps);
240     /**
241      * @brief Analyze userDatas.
242      * @param userId Indicates the userId.
243      * @param userDataDir Indicates the userDataDir.
244      * @param userDataBundleName Indicates the userDataBundleName.
245      * @param userMaps Indicates the userMaps to save userInfo.
246      * @return Returns true if analyze infos successfully; returns false otherwise.
247      */
248     bool AnalyzeUserData(
249         int32_t userId, const std::string &userDataDir, const std::string &userDataBundleName,
250         std::map<std::string, std::vector<InnerBundleUserInfo>> &userMaps);
251     /**
252      * @brief ReInstall all Apps from installDir.
253      * @return Returns the ResultCode indicates the result of this action.
254      */
255     ResultCode ReInstallAllInstallDirApps();
256     /**
257      * @brief Combine install infos and userInfos.
258      * @param installInfos Indicates the installInfos.
259      * @param userInfoMaps Indicates the userInfoMaps.
260      * @return Returns true if combine infos successfully; returns false otherwise.
261      */
262     bool CombineBundleInfoAndUserInfo(
263         const std::map<std::string, std::vector<InnerBundleInfo>> &installInfos,
264         const std::map<std::string, std::vector<InnerBundleUserInfo>> &userInfoMaps);
265     /**
266      * @brief Save recover info to cache.
267      * @param info Indicates the InnerBundleInfo.
268      * @return
269      */
270     void SaveInstallInfoToCache(InnerBundleInfo &info);
271     /**
272      * @brief Scan dir by scanMode and resultMode, this function will perform
273      *        scan through installd because installd has higher permissions.
274      * @param scanMode Indicates the scanMode,
275      *        which maybe SUB_FILE_ALL SUB_FILE_DIR or SUB_FILE_FILE.
276      * @param resultMode Indicates the resultMode,
277      *        which maybe ABSOLUTE_PATH or RELATIVE_PATH.
278      * @param resultList Indicates the scan resultList.
279      * @return Returns true if Scan successfully; returns false otherwise.
280      */
281     bool ScanDir(const std::string& dir, ScanMode scanMode,
282         ResultMode resultMode, std::vector<std::string> &resultList);
283     /**
284      * @brief Bundle boot start event.
285      * @return
286      */
287     void BundleBootStartEvent();
288     /**
289      * @brief Bundle reboot start event.
290      * @return
291      */
292     void BundleRebootStartEvent();
293     /**
294      * @brief start boot scan.
295      * @param userId Indicates the userId.
296      * @return
297      */
298     void OnBundleBootStart(int32_t userId = Constants::UNSPECIFIED_USERID);
299     /**
300      * @brief Process boot bundle install from scan.
301      * @param userId Indicates the userId.
302      * @return
303      */
304     void ProcessBootBundleInstallFromScan(int32_t userId);
305     /**
306      * @brief Process bundle install by scanInfos.
307      * @param userId Indicates the userId.
308      * @return
309      */
310     void InnerProcessBootPreBundleProFileInstall(int32_t userId);
311     /**
312      * @brief Install bundles by scanDir.
313      * @param scanDir Indicates the scanDir.
314      * @param appType Indicates the bundle type.
315      * @param userId Indicates userId.
316      * @return
317      */
318     void ProcessSystemBundleInstall(
319         const std::string &scanDir,
320         Constants::AppType appType,
321         int32_t userId = Constants::UNSPECIFIED_USERID);
322     /**
323      * @brief Install system shared bundle.
324      * @param sharedBundlePath Indicates the path of shared bundle.
325      * @param appType Indicates the bundle type.
326      * @return
327      */
328     void ProcessSystemSharedBundleInstall(const std::string &sharedBundlePath, Constants::AppType appType);
329     /**
330      * @brief start reboot scan.
331      * @return
332      */
333     void OnBundleRebootStart();
334     /**
335      * @brief Process reboot bundle.
336      * @return
337      */
338     void ProcessRebootBundle();
339     /**
340      * @brief Obtains the PreInstallBundleInfo objects.
341      * @return Returns true if this function is successfully called; returns false otherwise.
342      */
343     bool LoadAllPreInstallBundleInfos();
344     /**
345      * @brief Process reboot bundle install.
346      * @return
347      */
348     void ProcessRebootBundleInstall();
349     /**
350      * @brief Process reboot bundle install by scanInfos.
351      * @return
352      */
353     void ProcessReBootPreBundleProFileInstall();
354     /**
355      * @brief Process reboot bundle install from scan.
356      * @return
357      */
358     void ProcessRebootBundleInstallFromScan();
359     /**
360      * @brief Process reboot install bundles by bundleList.
361      * @param bundleList Indicates store bundle list.
362      * @param appType Indicates the bundle type.
363      * @return
364      */
365     void InnerProcessRebootBundleInstall(
366         const std::list<std::string> &bundleList, Constants::AppType appType);
367     /**
368      * @brief Process reboot install shared bundles by bundleList.
369      * @param bundleList Indicates store bundle list.
370      * @param appType Indicates the bundle type.
371      * @return
372      */
373     void InnerProcessRebootSharedBundleInstall(const std::list<std::string> &bundleList, Constants::AppType appType);
374     /**
375      * @brief Process reboot install system hsp by bundleList.
376      * @param scanPathList Indicates store bundle list.
377      * @return
378      */
379     void InnerProcessRebootSystemHspInstall(const std::list<std::string> &scanPathList);
380     /**
381      * @brief Reboot uninstall system and system vendor bundles.
382      * @return
383      */
384     void ProcessRebootBundleUninstall();
385     /**
386      * @brief Reboot uninstall appFwkService bundles.
387      * @return
388      */
389     void ProcessRebootAppServiceUninstall();
390     /**
391      * @brief Get bundle dir by scan.
392      * @param bundleDirs Indicates the return bundleDirs.
393      * @return
394      */
395     void GetBundleDirFromScan(std::list<std::string> &bundleDirs);
396     /**
397      * @brief Process scan dir.
398      * @param dir Indicates the dir.
399      * @param bundleDirs Indicates the return bundleDirs.
400      * @return
401      */
402     static void ProcessScanDir(const std::string &dir, std::list<std::string> &bundleDirs);
403     /**
404      * @brief Process parse pre bundle profile.
405      * @param dir Indicates the dir.
406      * @return
407      */
408     static void ParsePreBundleProFile(const std::string &dir);
409     static void FilterVersionSpecialCustomApps(std::set<PreScanInfo> &installList);
410     /**
411      * @brief Set the flag indicates that all system and vendor applications installed.
412      * @return
413      */
414     void CreateAppInstallDir() const;
415     void SetAllInstallFlag() const;
416     /**
417      * @brief Check and parse hap.
418      * @param hapFilePath Indicates the absolute file path of the HAP.
419      * @param isPreInstallApp Indicates the hap is preInstallApp or not.
420      * @param infos Indicates the obtained BundleInfo object.
421      * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise.
422      */
423     bool CheckAndParseHapFiles(const std::string &hapFilePath,
424         bool isPreInstallApp, std::unordered_map<std::string, InnerBundleInfo> &infos);
425     bool CheckAndParseHapFiles(const std::vector<std::string> &realPaths,
426         bool isPreInstallApp, std::unordered_map<std::string, InnerBundleInfo> &infos);
427     /**
428      * @brief Parse hap.
429      * @param hapFilePath Indicates the absolute file path of the HAP.
430      * @param infos Indicates the obtained BundleInfo object.
431      * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise.
432      */
433     static bool ParseHapFiles(
434         const std::string &hapFilePath,
435         std::unordered_map<std::string, InnerBundleInfo> &infos);
436     /**
437      * @brief OTA Install system app and system vendor bundles.
438      * @param filePaths Indicates the filePaths.
439      * @param appType Indicates the bundle type.
440      * @param removable Indicates whether it can be removed.
441      * @return Returns true if this function called successfully; returns false otherwise.
442      */
443     bool OTAInstallSystemBundle(
444         const std::vector<std::string> &filePaths,
445         Constants::AppType appType,
446         bool removable);
447 
448     /**
449      * @brief OTA Install system app and system vendor bundles.
450      * @param filePaths Indicates the filePaths.
451      * @param bundleName Indicates the bundleName.
452      * @param appType Indicates the bundle type.
453      * @param removable Indicates whether it can be removed.
454      * @return Returns true if this function called successfully; returns false otherwise.
455      */
456     static bool OTAInstallSystemBundleNeedCheckUser(
457         const std::vector<std::string> &filePaths,
458         const std::string &bundleName,
459         Constants::AppType appType,
460         bool removable);
461     /**
462      * @brief OTA Install system app and system vendor bundles.
463      * @param filePaths Indicates the filePaths.
464      * @param bundleName Indicates the bundleName.
465      * @param appType Indicates the bundle type.
466      * @param removable Indicates whether it can be removed.
467      * @param userIds Indicates the user to which the app needs to be installed.
468      * @return Returns true if this function called successfully; returns false otherwise.
469      */
470     static bool OTAInstallSystemBundleTargetUser(
471         const std::vector<std::string> &filePaths,
472         const std::string &bundleName,
473         Constants::AppType appType,
474         bool removable,
475         const std::vector<int32_t> &userIds);
476     /**
477      * @brief OTA Install system app and system vendor shared bundles.
478      * @param filePaths Indicates the filePaths.
479      * @param appType Indicates the bundle type.
480      * @param removable Indicates whether it can be removed.
481      * @return Returns true if this function called successfully; returns false otherwise.
482      */
483     bool OTAInstallSystemSharedBundle(
484         const std::vector<std::string> &filePaths,
485         Constants::AppType appType,
486         bool removable);
487     /**
488      * @brief OTA Install system hsp.
489      * @param filePaths Indicates the filePaths.
490      * @return Returns ERR_OK if this function called successfully; returns false otherwise.
491      */
492     ErrCode OTAInstallSystemHsp(const std::vector<std::string> &filePaths);
493     /**
494      * @brief Used to determine whether the module has been installed. If the installation has
495      *        been uninstalled, OTA install and upgrade will not be allowed.
496      * @param bundleName Indicates the bundleName.
497      * @param bundlePath Indicates the bundlePath.
498      * @return Returns true if this function called successfully; returns false otherwise.
499      */
500     bool HasModuleSavedInPreInstalledDb(
501         const std::string &bundleName, const std::string &bundlePath);
502     /**
503      * @brief Delete preInstallInfo to Db.
504      * @param bundleName Indicates the bundleName.
505      * @param bundlePath Indicates the bundlePath.
506      */
507     void DeletePreInfoInDb(
508         const std::string &bundleName, const std::string &bundlePath, bool bundleLevel);
509     /**
510      * @brief Add parseInfos to map.
511      * @param bundleName Indicates the bundleName.
512      * @param infos Indicates the infos.
513      */
514     void AddParseInfosToMap(const std::string &bundleName,
515         const std::unordered_map<std::string, InnerBundleInfo> &infos);
516     /**
517      * @brief Clear cache.
518      */
519     void ClearCache();
520     /**
521      * @brief Judge whether the preInstall app can be removable.
522      * @param path Indicates the path.
523      * @return Returns true if the preInstall is removable; returns false otherwise.
524      */
525     bool IsPreInstallRemovable(const std::string &path);
526 
527     void AddTasks(const std::map<int32_t, std::vector<PreScanInfo>,
528         std::greater<int32_t>> &taskMap, int32_t userId);
529     void AddTaskParallel(
530         int32_t taskPriority, const std::vector<PreScanInfo> &tasks, int32_t userId);
531 
532     bool InnerMultiProcessBundleInstall(
533         const std::unordered_map<std::string, std::pair<std::string, bool>> &needInstallMap,
534         Constants::AppType appType);
535 
536     void ProcessCheckAppDataDir();
537     void InnerProcessCheckAppDataDir();
538 
539     void ProcessCheckAppLogDir();
540     void InnerProcessCheckAppLogDir();
541     void ProcessCheckAppFileManagerDir();
542     void InnerProcessCheckAppFileManagerDir();
543     void ProcessCheckPreinstallData();
544     void InnerProcessCheckPreinstallData();
545     void ProcessCheckShaderCacheDir();
546     void InnerProcessCheckShaderCacheDir();
547     void ProcessCheckSystemOptimizeShaderCacheDir();
548     void ProcessCheckCloudShaderDir();
549     void InnerProcessCheckCloudShaderDir();
550     void InnerProcessCheckCloudShaderCommonDir(const int32_t uid, const int32_t gid);
551     void ProcessNewBackupDir();
552     void ProcessCheckRecoverableApplicationInfo();
553     void InnerProcessCheckRecoverableApplicationInfo();
554     void ProcessCheckInstallSource();
555     void InnerProcessCheckInstallSource();
556     std::string ConvertApplicationFlagToInstallSource(int32_t flag);
557 
558     bool InnerProcessUninstallForExistPreBundle(const BundleInfo &installedInfo);
559 
560     void PrepareBundleDirQuota(const std::string &bundleName, const int32_t uid,
561         const std::string &bundleDataDirPath, const int32_t limitSize) const;
562     void ParseSizeFromProvision(const std::string &bundleName, int32_t &sizeMb) const;
563     void RefreshQuotaForAllUid();
564     void InnerProcessStockBundleRouterInfo();
565 
566     bool InnerProcessUninstallModule(const BundleInfo &bundleInfo,
567         const std::unordered_map<std::string, InnerBundleInfo> &infos, bool &isDownGrade);
568     bool InnerProcessUninstallAppServiceModule(const InnerBundleInfo &innerBundleInfo,
569         const std::unordered_map<std::string, InnerBundleInfo> &infos, bool &isDownGrade);
570 
571     void ProcessCheckAppExtensionAbility();
572     void InnerProcessCheckAppExtensionAbility();
573     void UpdateExtensionType();
574     bool IsSystemUpgrade();
575     bool IsTestSystemUpgrade();
576     bool IsSystemFingerprintChanged();
577     std::string GetCurSystemFingerprint();
578     static std::string GetOldSystemFingerprint();
579     bool GetSystemParameter(const std::string &key, std::string &value);
580     void SaveSystemFingerprint();
581     void HandlePreInstallException();
582     static bool IsHapPathExist(const BundleInfo &bundleInfo);
583     static bool IsHspPathExist(const InnerBundleInfo &innerBundleInfo);
584 
585     bool FetchInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &innerBundleInfo);
586     void GetPreInstallDirFromLoadProFile(std::vector<std::string> &bundleDirs);
587     void GetPreInstallDirFromScan(std::vector<std::string> &bundleDirs);
588 
589     void InnerProcessBootSystemHspInstall();
590     void ProcessSystemHspInstall(const PreScanInfo &preScanInfo);
591     bool ProcessSystemHspInstall(const std::string &systemHspDir);
592 
593     static void AddStockAppProvisionInfoByOTA(const std::string &bundleName, const std::string &filePath);
594     void UpdateAppDataSelinuxLabel(const std::string &bundleName, const std::string &apl,
595         bool isPreInstall, bool debug);
596     static bool IsQuickfixPatchApp(const std::string &bundleName, uint32_t versionCode);
597     bool HotPatchAppProcessing(const std::string &bundleName, uint32_t hasInstallVersionCode, uint32_t hapVersionCode,
598         std::vector<int32_t> &userIds);
599     static bool GetValueFromJson(nlohmann::json &jsonObject);
600     static void PatchSystemHspInstall(const std::string &path, bool isOta);
601     static void PatchSharedHspInstall(const std::string &path);
602     static void PatchSystemBundleInstall(const std::string &path, bool isOta);
603     void HandleOTACodeEncryption();
604     void SaveCodeProtectFlag();
605 #ifdef USE_PRE_BUNDLE_PROFILE
606     void UpdateRemovable(const std::string &bundleName, bool removable);
607     void UpdateAllPrivilegeCapability();
608     void UpdatePrivilegeCapability(const PreBundleConfigInfo &preBundleConfigInfo);
609     bool MatchSignature(const PreBundleConfigInfo &configInfo, const std::string &signature);
610     bool MatchOldSignatures(const PreBundleConfigInfo &configInfo, const std::vector<std::string> &appSignatures);
611     void UpdateTrustedPrivilegeCapability(const PreBundleConfigInfo &preBundleConfigInfo);
612 #endif
613     void DeletePreInstallExceptionAppService(const std::string &bundleDir);
614     void SavePreInstallExceptionAppService(const std::string &bundleDir);
615     void HandlePreInstallAppServicePathsException(std::shared_ptr<PreInstallExceptionMgr> preInstallExceptionMgr,
616         const std::set<std::string> &exceptionAppServicePaths);
617     void HandlePreInstallAppPathsException(
618         std::shared_ptr<PreInstallExceptionMgr> preInstallExceptionMgr, const std::set<std::string> &exceptionPaths);
619     void HandlePreInstallAppServiceBundleNamesException(std::shared_ptr<PreInstallExceptionMgr> preInstallExceptionMgr,
620         const std::set<std::string> &exceptionAppServiceBundleNames);
621     void HandlePreInstallBundleNamesException(std::shared_ptr<PreInstallExceptionMgr> preInstallExceptionMgr,
622         const std::set<std::string> &exceptionBundleNames);
623     bool IsModuleUpdate();
624     void HandleModuleUpdate();
625     bool GetModuleUpdatePathList(
626         std::map<std::string, std::vector<std::string>> &moduleUpdateAppServiceMap,
627         std::map<std::string, std::vector<std::string>> &moduleUpdateNotAppServiceMap);
628     bool HandleInstallHmp(
629         const std::map<std::string, std::vector<std::string>> &moduleUpdateAppServiceMap,
630         const std::map<std::string, std::vector<std::string>> &moduleUpdateNotAppServiceMap);
631     bool HandleInstallModuleUpdateSystemHsp(const std::vector<std::string> &appDirList);
632     bool HandleInstallModuleUpdateNormalApp(const std::vector<std::string> &appDirList);
633     bool CheckIsModuleUpdate(const std::string &str);
634     bool CheckAppIsUpdatedByUser(const std::string& appDir);
635     void FilterModuleUpdate(const std::vector<std::string> &preInstallDirs,
636         std::map<std::string, std::vector<std::string>> &moduleUpdateMap, bool isAppService);
637     std::string GetBundleNameByPreInstallPath(const std::string& path);
638     bool GetRemovableInfo(const std::string& bundleDir);
639     void GetHmpList(std::vector<std::string> &hmpList,
640         std::map<std::string, std::vector<std::string>> &moduleUpdateAppServiceMap,
641         std::map<std::string, std::vector<std::string>> &moduleUpdateNotAppServiceMap);
642     void ModuleUpdateRollBack();
643     void ProcessModuleUpdateSystemParameters();
644     void HandleHmpUninstall();
645     void SaveHmpBundlePathInfo(const std::string &hmpName,
646         const std::string &bundleName, const std::string bundlePath, bool isAppService);
647     void ListeningUserUnlocked() const;
648     void RemoveUnreservedSandbox() const;
649     void HandleSceneBoard() const;
650     static void InnerProcessStockBundleProvisionInfo();
651     bool UpdateModuleByHash(const BundleInfo &oldBundleInfo, const InnerBundleInfo &newInfo) const;
652     void CheckALLResourceInfo();
653     void InnerProcessAllDynamicIconInfoWhenOta();
654     void InnerProcessAllThemeAndDynamicIconInfoWhenOta(
655         const std::unordered_map<std::string, std::pair<std::string, bool>> &needInstallMap);
656     // Used to add bundle resource Info that does not exist in rdb when OTA.
657     void static ProcessBundleResourceInfo();
658     // scan all bundle data group info
659     void ProcessAllBundleDataGroupInfo();
660     // Used to send update failed event
661     void SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo);
662     void SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo, const int32_t errorCode);
663     void ProcessAppTmpPath();
664     void UpdatePreinstallDB(const std::unordered_map<std::string, std::pair<std::string, bool>> &needInstallMap);
665     void UpdatePreinstallDBForNotUpdatedBundle(const std::string &bundleName,
666         const std::unordered_map<std::string, InnerBundleInfo> &innerBundleInfos);
667     void InnerProcessRebootUninstallWrongBundle();
668     bool InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo);
669     bool IsPathExistInInstalledBundleInfo(const std::string &path, const BundleInfo &bundleInfo);
670     void ProcessCheckAppEl1Dir();
671     void static ProcessCheckAppEl1DirTask();
672     // check el2 data dir for all userids's bundleinfos
673     void CheckAndCreateShareFilesSubDataDirs();
674     void CleanAllBundleShaderCache() const;
675     void CleanTempDir() const;
676     bool CheckIsBundleUpdatedByHapPath(const BundleInfo &bundleInfo);
677     void CheckBundleProvisionInfo();
678     void CheckBundleCloneEl1ShaderCacheLocal(const std::string &bundleName, int32_t appIndex,
679         int32_t userId, int32_t uid);
680     void CleanBundleCloneEl1ShaderCacheLocal(const std::string &bundleName, int32_t appIndex,
681         int32_t userId);
682     void CheckAllBundleEl1ShaderCacheLocal();
683     void CleanAllBundleEl1ShaderCacheLocal();
684     void InnerProcessBootCheckOnDemandBundle();
685     void ProcessRebootCheckOnDemandBundle();
686     bool ParseOnDemandHapFiles(const std::string &hapFilePath,
687         std::vector<Security::Verify::HapVerifyResult> &hapVerifyResults,
688         std::unordered_map<std::string, InnerBundleInfo> &infos);
689     void ConvertToOnDemandInstallBundleInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos,
690         PreInstallBundleInfo &preInstallBundleInfo);
691     void SavePreloadAppUninstallInfo(const PreInstallBundleInfo &info,
692         std::vector<std::string> &preloadBundleNames);
693     void SaveUninstalledPreloadAppToFile(const std::vector<std::string> &preloadBundleNames);
694     void CreateUninstalledPreloadDir();
695     void RemoveUninstalledPreloadFile();
696     void ProcessUpdatePermissions();
697     bool IsPermissionsUpdated();
698     bool SaveUpdatePermissionsFlag();
699     bool CleanAllBundleEl1ArkStartupCacheLocal();
700     bool ProcessCheckSystemOptimizeDir();
701 #ifdef WEBVIEW_ENABLE
702     void NotifyFWKAfterBmsStart();
703 #endif
704 
705     ErrCode CheckSystemOptimizeBundleShaderCache(const std::string &bundleName,
706         int32_t appIndex, int32_t userId, int32_t uid);
707     ErrCode CheckSystemOptimizeShaderCache();
708     ErrCode CleanSystemOptimizeBundleShaderCache(const std::string &bundleName,
709         int32_t appIndex, int32_t userId);
710     ErrCode CleanSystemOptimizeShaderCache();
711 
712     // Used to mark Whether trigger OTA check
713     bool needRebootOta_ = false;
714     // Used to notify bundle scan status
715     bool needNotifyBundleScanStatus_ = false;
716 
717     bool hasLoadAllPreInstallBundleInfosFromDb_ = false;
718     // Used to mark module update status depend on system parameter
719     ModuleUpdateStatus moduleUpdateStatus_ = ModuleUpdateStatus::DEFAULT;
720     // Used to save the information parsed by Hap in the scanned directory.
721     std::map<std::string, std::unordered_map<std::string, InnerBundleInfo>> hapParseInfoMap_;
722     // Used to save application information that already exists in the Db.
723     std::map<std::string, PreInstallBundleInfo> loadExistData_;
724     // Used to mark every hmp install result
725     std::map<std::string, bool> moduleUpdateInstallResults_;
726     // Used to indicates not appService bundleName in hmp
727     std::map<std::string, std::set<std::string>> moduleUpdateNormalApp_;
728     // Used to indicates appService bundleName in hmp
729     std::map<std::string, std::set<std::string>> moduleUpdateAppService_;
730     // key is bundleName, value is HmpBundlePathInfo
731     std::map<std::string, HmpBundlePathInfo> hmpBundlePathInfos_;
732 };
733 }  // namespace AppExecFwk
734 }  // namespace OHOS
735 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_EVENT_HANDLER_H
736