flutter_flutter/shell/platform/android/apk_asset_provider.h
Jonah Williams 15c587404c
Preserve specified AssetResolvers when performing a hot restart or updating the asset directory (#21611)
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.
2020-10-08 09:22:01 -07:00

45 lines
1.2 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.
#ifndef FLUTTER_ASSETS_APK_ASSET_PROVIDER_H_
#define FLUTTER_ASSETS_APK_ASSET_PROVIDER_H_
#include <android/asset_manager_jni.h>
#include <jni.h>
#include "flutter/assets/asset_resolver.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/platform/android/scoped_java_ref.h"
namespace flutter {
class APKAssetProvider final : public AssetResolver {
public:
explicit APKAssetProvider(JNIEnv* env,
jobject assetManager,
std::string directory);
~APKAssetProvider() override;
private:
fml::jni::ScopedJavaGlobalRef<jobject> java_asset_manager_;
AAssetManager* assetManager_;
const std::string directory_;
// |flutter::AssetResolver|
bool IsValid() const override;
// |flutter::AssetResolver|
bool IsValidAfterAssetManagerChange() const override;
// |flutter::AssetResolver|
std::unique_ptr<fml::Mapping> GetAsMapping(
const std::string& asset_name) const override;
FML_DISALLOW_COPY_AND_ASSIGN(APKAssetProvider);
};
} // namespace flutter
#endif // FLUTTER_ASSETS_APK_ASSET_PROVIDER_H