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_ACE_ADAPTER_OHOS_ENTRANCE_HAP_ASSET_PROVIDER_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_HAP_ASSET_PROVIDER_H 18 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 23 #include "extractor.h" 24 #include "flutter/fml/mapping.h" 25 26 #include "base/resource/asset_manager.h" 27 #include "base/utils/macros.h" 28 #include "core/common/flutter/flutter_asset_manager.h" 29 30 namespace OHOS::Ace { 31 class ACE_EXPORT HapAssetProvider : public FlutterAssetProvider { 32 DECLARE_ACE_TYPE(HapAssetProvider, FlutterAssetProvider); 33 34 public: 35 HapAssetProvider() = default; 36 ~HapAssetProvider() override = default; 37 38 bool Initialize(const std::string& hapPath, const std::vector<std::string>& assetBasePaths, bool useCache = true); 39 40 std::unique_ptr<fml::Mapping> GetAsMapping(const std::string& assetName) const override; 41 42 bool IsValid() const override; 43 44 std::string GetAssetPath(const std::string& assetName, bool isAddHapPath) override; 45 46 void GetAssetList(const std::string& path, std::vector<std::string>& assetList) override; 47 48 bool GetFileInfo(const std::string& fileName, MediaFileInfo& fileInfo) const override; 49 50 void Reload() override; 51 52 private: 53 mutable std::mutex mutex_; 54 std::string hapPath_; 55 std::string loadPath_; 56 std::shared_ptr<AbilityBase::Extractor> runtimeExtractor_; 57 std::vector<std::string> assetBasePaths_; 58 }; 59 } // namespace OHOS::Ace 60 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_HAP_ASSET_PROVIDER_H 61