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