• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_ACE_ADAPTER_OHOS_ENTRANCE_FORM_MODULE_PRELOADER_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_FORM_MODULE_PRELOADER_H
18 
19 #include <unordered_set>
20 #include <vector>
21 
22 #include "core/common/flutter/flutter_asset_manager.h"
23 
24 namespace OHOS::Ace {
25 class FormModulePreloader {
26 public:
27     /**
28      * @brief Get a list of components used by cards in the specified bundle.
29      * @param bundleName The name of target bundle.
30      * @param formModuleList Output, the list of components.
31      * @return Returns TRUE on success, FALSE on failure.
32      */
33     static bool CreateFormModuleList(const std::string& bundleName, std::unordered_set<std::string>& formModuleList);
34     /**
35      * @brief In the card bundle upgrade condition, get the list of newly added components.
36      * @param bundleName The name of target bundle.
37      * @param formModuleList Output, the list of newly added components.
38      * @return Returns TRUE on success, FALSE on failure.
39      */
40     static bool GetNewFormModuleList(const std::string& bundleName, std::unordered_set<std::string>& formModuleList);
41 
42 private:
43     FormModulePreloader() = default;
44     ~FormModulePreloader() = default;
45 
46     static bool ReadFormModuleList(
47         const std::string& bundleName, std::unordered_set<std::string>& formModuleList, bool isReloadCondition);
48 
49     static void GetHapPathsByBundleName(const std::string& bundleName, std::vector<std::string>& hapPaths);
50 
51     static bool ReadFileFromAssetManager(
52         const RefPtr<AssetManager>& assetManager, const std::string& fileName, std::string& content);
53 
54     static bool GetFormEtsFilePath(
55         const RefPtr<AssetManager>& assetManager, std::unordered_set<std::string>& filePaths);
56 
57     static bool ParseComponentCollectionJson(
58         const std::string& bundleName, const std::unordered_set<std::string>& formEtsFilePaths,
59         const std::string& content, std::unordered_set<std::string>& formModuleList, bool isReloadCondition);
60 
61     static bool IsFormEtsFilePath(const std::unordered_set<std::string>& formEtsFilePaths, std::string path);
62 
63     static RefPtr<AssetManager> CreateAssetManager(const std::string& hapPath);
64 };
65 } // namespace OHOS::Ace
66 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_FORM_MODULE_PRELOADER_H
67