• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/resource/asset_manager.h"
24 #include "base/utils/macros.h"
25 #include "core/common/flutter/flutter_asset_manager.h"
26 
27 #include "flutter/fml/mapping.h"
28 #include "runtime_extractor.h"
29 
30 namespace OHOS::Ace {
31 
32 class ACE_EXPORT HapAssetProvider : public FlutterAssetProvider {
33     DECLARE_ACE_TYPE(HapAssetProvider, FlutterAssetProvider);
34 
35 public:
36     HapAssetProvider() = default;
37     ~HapAssetProvider() override = default;
38 
39     bool Initialize(const std::string& hapPath, const std::vector<std::string>& assetBasePaths);
40 
41     std::unique_ptr<fml::Mapping> GetAsMapping(const std::string& assetName) const override;
42 
43     bool IsValid() const override;
44 
45     std::string GetAssetPath(const std::string& assetName) override;
46 
47     void GetAssetList(const std::string& path, std::vector<std::string>& assetList) override;
48 
49 private:
50     mutable std::mutex mutex_;
51     std::string hapPath_;
52     std::shared_ptr<AbilityRuntime::RuntimeExtractor> runtimeExtractor_;
53     std::vector<std::string> assetBasePaths_;
54 };
55 
56 } // namespace OHOS::Ace
57 
58 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_HAP_ASSET_PROVIDER_H
59