mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Follow up from #21436 . That PR works for all embeddings except for Android, which creates a special JNI AssetResolver. Since the shell cannot recreate this resolver, update the logic to preserve existing resolvers instead.
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/assets/directory_asset_bundle.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "flutter/fml/eintr_wrapper.h"
|
|
#include "flutter/fml/file.h"
|
|
#include "flutter/fml/mapping.h"
|
|
|
|
namespace flutter {
|
|
|
|
DirectoryAssetBundle::DirectoryAssetBundle(
|
|
fml::UniqueFD descriptor,
|
|
bool is_valid_after_asset_manager_change)
|
|
: descriptor_(std::move(descriptor)) {
|
|
if (!fml::IsDirectory(descriptor_)) {
|
|
return;
|
|
}
|
|
is_valid_after_asset_manager_change_ = is_valid_after_asset_manager_change;
|
|
is_valid_ = true;
|
|
}
|
|
|
|
DirectoryAssetBundle::~DirectoryAssetBundle() = default;
|
|
|
|
// |AssetResolver|
|
|
bool DirectoryAssetBundle::IsValid() const {
|
|
return is_valid_;
|
|
}
|
|
|
|
// |AssetResolver|
|
|
bool DirectoryAssetBundle::IsValidAfterAssetManagerChange() const {
|
|
return is_valid_after_asset_manager_change_;
|
|
}
|
|
|
|
// |AssetResolver|
|
|
std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
|
|
const std::string& asset_name) const {
|
|
if (!is_valid_) {
|
|
FML_DLOG(WARNING) << "Asset bundle was not valid.";
|
|
return nullptr;
|
|
}
|
|
|
|
auto mapping = std::make_unique<fml::FileMapping>(fml::OpenFile(
|
|
descriptor_, asset_name.c_str(), false, fml::FilePermission::kRead));
|
|
|
|
if (!mapping->IsValid()) {
|
|
return nullptr;
|
|
}
|
|
|
|
return mapping;
|
|
}
|
|
|
|
} // namespace flutter
|