• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "bundle_constants.h"
20 #include "bundle_data_mgr.h"
21 #include "event_handler.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 class BundleMgrService;
26 
27 class BMSEventHandler : public EventHandler {
28 public:
29     explicit BMSEventHandler(const std::shared_ptr<EventRunner> &runner);
30     virtual ~BMSEventHandler() override;
31     /**
32      * @brief Process the event of install system bundles.
33      * @param event Indicates the event to be processed.
34      * @return
35      */
36     virtual void ProcessEvent(const InnerEvent::Pointer &event) override;
37 
38     enum {
39         BUNDLE_SCAN_START = 1,
40         BUNDLE_SCAN_FINISHED,
41         BMS_START_FINISHED,
42         BUNDLE_REBOOT_SCAN_START,
43     };
44 
45 private:
46     /**
47      * @brief Install system and system vendor bundles.
48      * @param appType Indicates the bundle type.
49      * @param userId Indicates userId.
50      * @return
51      */
52     void ProcessSystemBundleInstall(
53         Constants::AppType appType, int32_t userId = Constants::UNSPECIFIED_USERID) const;
54     /**
55      * @brief Set the flag indicates that all system and vendor applications installed.
56      * @return
57      */
58     void SetAllInstallFlag() const;
59     /**
60      * @brief start scan.
61      * @param userId Indicates the userId.
62      * @return
63      */
64     void OnStartScanning(int32_t userId = Constants::UNSPECIFIED_USERID);
65     /**
66      * @brief start scan.
67      * @param userId Indicates the userId.
68      * @return
69      */
70     void RebootStartScanning(int32_t userId = Constants::UNSPECIFIED_USERID);
71     /**
72      * @brief Install system and system vendor bundles.
73      * @param userId Indicates userId.
74      * @return
75      */
76     void RebootProcessSystemBundle(int32_t userId = Constants::UNSPECIFIED_USERID);
77     /**
78      * @brief Get bundleinfo of HAP by path.
79      * @param hapFilePath Indicates the absolute file path of the HAP.
80      * @param infos Indicates the obtained BundleInfo object.
81      * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise.
82      */
83     bool ParseHapFiles(const std::string &hapFilePath,
84         std::unordered_map<std::string, InnerBundleInfo> &infos);
85     /**
86      * @brief Reboot install system and system vendor bundles.
87      * @param bundleList Indicates store bundle list.
88      * @param appType Indicates the bundle type.
89      * @return
90      */
91     void RebootBundleInstall(
92         const std::list<std::string> &bundleList, Constants::AppType appType);
93     /**
94      * @brief Reboot uninstall system and system vendor bundles.
95      * @return
96      */
97     void RebootBundleUninstall();
98     /**
99      * @brief To check the version code and bundleName in all haps.
100      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
101      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
102      */
103     ErrCode CheckAppLabelInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos);
104     /**
105      * @brief OTA Install system app and system vendor bundles.
106      * @param filePath Indicates the filePath.
107      * @param appType Indicates the bundle type.
108      * @return Returns true if this function called successfully; returns false otherwise.
109      */
110     bool OTAInstallSystemBundle(const std::string &filePath, Constants::AppType appType);
111     /**
112      * @brief Used to determine whether the module has been installed. If the installation has
113      *        been uninstalled, OTA install and upgrade will not be allowed.
114      * @param bundleName Indicates the bundleName.
115      * @param bundlePath Indicates the bundlePath.
116      * @return Returns true if this function called successfully; returns false otherwise.
117      */
118     bool HasModuleSavedInPreInstalledDb(
119         const std::string &bundleName, const std::string &bundlePath);
120     /**
121      * @brief Delete preInstallInfo to Db.
122      * @param bundleName Indicates the bundleName.
123      * @param bundlePath Indicates the bundlePath.
124      */
125     void DeletePreInfoInDb(
126         const std::string &bundleName, const std::string &bundlePath, bool bundleLevel);
127     /**
128      * @brief Add parseInfos to map.
129      * @param bundleName Indicates the bundleName.
130      * @param infos Indicates the infos.
131      */
132     void AddParseInfosToMap(const std::string &bundleName,
133         const std::unordered_map<std::string, InnerBundleInfo> &infos);
134 
135     // Used to save the information parsed by Hap in the scanned directory.
136     std::map<std::string, std::unordered_map<std::string, InnerBundleInfo>> hapParseInfoMap_;
137     // used to save application information that already exists in the Db.
138     std::map<std::string, PreInstallBundleInfo> loadExistData_;
139 };
140 }  // namespace AppExecFwk
141 }  // namespace OHOS
142 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_MGR_SERVICE_EVENT_HANDLER_H
143