From 733d65dd7bcbc2d7cffa0bf982dcdb68a6b63158 Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Fri, 28 Dec 2018 10:34:47 -0800 Subject: [PATCH] Support loading flutter assets from dynamic patch (flutter/engine#7308) This replicates similar logic found in ApkAssetProvider that locates assets by their short name in a sudbirectory inside of an archive file, instead of only at the root of archive. --- engine/src/flutter/assets/zip_asset_store.cc | 6 +++--- engine/src/flutter/assets/zip_asset_store.h | 6 ++++-- .../shell/platform/android/platform_view_android_jni.cc | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/assets/zip_asset_store.cc b/engine/src/flutter/assets/zip_asset_store.cc index 1b6cb126246..97228f96087 100644 --- a/engine/src/flutter/assets/zip_asset_store.cc +++ b/engine/src/flutter/assets/zip_asset_store.cc @@ -22,8 +22,8 @@ void UniqueUnzipperTraits::Free(void* file) { unzClose(file); } -ZipAssetStore::ZipAssetStore(std::string file_path) - : file_path_(std::move(file_path)) { +ZipAssetStore::ZipAssetStore(std::string file_path, std::string directory) + : file_path_(std::move(file_path)), directory_(std::move(directory)) { BuildStatCache(); } @@ -43,8 +43,8 @@ std::unique_ptr ZipAssetStore::GetAsMapping( const std::string& asset_name) const { TRACE_EVENT1("flutter", "ZipAssetStore::GetAsMapping", "name", asset_name.c_str()); - auto found = stat_cache_.find(asset_name); + auto found = stat_cache_.find(directory_ + "/" + asset_name); if (found == stat_cache_.end()) { return nullptr; } diff --git a/engine/src/flutter/assets/zip_asset_store.h b/engine/src/flutter/assets/zip_asset_store.h index a026fb91d29..b8b66a7d4f5 100644 --- a/engine/src/flutter/assets/zip_asset_store.h +++ b/engine/src/flutter/assets/zip_asset_store.h @@ -23,7 +23,7 @@ using UniqueUnzipper = fml::UniqueObject; class ZipAssetStore final : public AssetResolver { public: - ZipAssetStore(std::string file_path); + ZipAssetStore(std::string file_path, std::string directory); ~ZipAssetStore() override; @@ -35,7 +35,9 @@ class ZipAssetStore final : public AssetResolver { : file_pos(p_file_pos), uncompressed_size(p_uncompressed_size) {} }; - std::string file_path_; + const std::string file_path_; + const std::string directory_; + mutable std::map stat_cache_; // |blink::AssetResolver| diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc index ccc8998cab8..e92d782b3f5 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc @@ -253,7 +253,7 @@ static void RunBundleAndSnapshotFromLibrary(JNIEnv* env, const auto file_ext_index = bundlepath.rfind("."); if (bundlepath.substr(file_ext_index) == ".zip") { asset_manager->PushBack( - std::make_unique(bundlepath)); + std::make_unique(bundlepath, "flutter_assets")); } else { asset_manager->PushBack( std::make_unique(fml::OpenDirectory(