1 /*
2 * Copyright (c) 2021-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 #include "core/common/flutter/flutter_asset_manager.h"
17
18 namespace OHOS::Ace {
19
GetAsset(const std::string & assetName)20 RefPtr<Asset> FlutterAssetManager::GetAsset(const std::string& assetName)
21 {
22 if (assetName.empty()) {
23 return nullptr;
24 }
25
26 for (const auto& provider : providers_) {
27 auto fileProvider = AceType::DynamicCast<FlutterAssetProvider>(provider);
28 if (fileProvider) {
29 auto mapping = fileProvider->GetAsMapping(assetName);
30 if (mapping) {
31 return AceType::MakeRefPtr<FlutterAsset>(std::move(mapping));
32 }
33 }
34 }
35 LOGW("find asset failed, name = %{public}s", assetName.c_str());
36 return nullptr;
37 }
38
GetAssetPath(const std::string & assetName)39 std::string FlutterAssetManager::GetAssetPath(const std::string& assetName)
40 {
41 for (const auto& provider : providers_) {
42 std::string path = provider->GetAssetPath(assetName);
43 if (!path.empty()) {
44 return path;
45 }
46 }
47 return "";
48 }
49
GetAssetList(const std::string & path,std::vector<std::string> & assetList) const50 void FlutterAssetManager::GetAssetList(const std::string& path, std::vector<std::string>& assetList) const
51 {
52 for (const auto& provider : providers_) {
53 provider->GetAssetList(path, assetList);
54 }
55 }
56
57 } // namespace OHOS::Ace
58