1 /*
2  * Copyright (c) 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_QUICK_FIX_BOOT_SCANNER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_QUICK_FIX_BOOT_SCANNER_H
18 
19 #include <map>
20 #include <vector>
21 
22 #include "bundle_data_mgr.h"
23 #include "quick_fix_data_mgr.h"
24 #include "quick_fix_state.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class QuickFixBootScanner : public DelayedSingleton<QuickFixBootScanner> {
30 public:
31     QuickFixBootScanner() = default;
32     virtual ~QuickFixBootScanner() = default;
33 
34     void ProcessQuickFixBootUp();
35 
36     void SetQuickFixState(const std::shared_ptr<QuickFixState> &state);
37 
38     ErrCode ProcessState() const;
39 
40     void RestoreQuickFix();
41 
42 private:
43     void ProcessQuickFixDir(const std::vector<std::string> &fileDir);
44     bool ReprocessQuickFix(const std::string &quickFixPath, const std::string &bundleName) const;
45     bool GetApplicationInfo(const std::string &bundleName, const std::string &quickFixPath, ApplicationInfo &info);
46     bool ProcessWithBundleHasQuickFixInfo(const std::string &bundleName, const std::string &hqfPath,
47         int32_t quickFixVersion, int32_t fileVersion);
48     void RemoveInvalidDir() const;
49 
50     std::shared_ptr<QuickFixState> state_ = nullptr;
51     std::shared_ptr<QuickFixDataMgr> quickFixDataMgr_ = nullptr;
52     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;
53     // key is bundleName
54     // value is versionCode --- hqfDir
55     std::map<std::string, std::pair<int32_t, std::string>> quickFixInfoMap_;
56     std::vector<std::string> invalidQuickFixDir_;
57 };
58 } // AppExecFwk
59 } // OHOS
60 
61 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_QUICK_FIX_BOOT_SCANNER_H