• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_ASSETS_APK_ASSET_PROVIDER_H_
6 #define FLUTTER_ASSETS_APK_ASSET_PROVIDER_H_
7 
8 #include <android/asset_manager_jni.h>
9 #include <jni.h>
10 
11 #include "flutter/assets/asset_resolver.h"
12 #include "flutter/fml/memory/ref_counted.h"
13 #include "flutter/fml/platform/android/scoped_java_ref.h"
14 
15 namespace flutter {
16 
17 class __attribute__((visibility("default"))) APKAssetProvider final
18     : public AssetResolver {
19  public:
20   explicit APKAssetProvider(JNIEnv* env,
21                             jobject assetManager,
22                             std::string directory);
23   ~APKAssetProvider() override;
24 
25  private:
26   fml::jni::ScopedJavaGlobalRef<jobject> java_asset_manager_;
27   AAssetManager* assetManager_;
28   const std::string directory_;
29 
30   // |flutter::AssetResolver|
31   bool IsValid() const override;
32 
33   // |flutter::AssetResolver|
34   std::unique_ptr<fml::Mapping> GetAsMapping(
35       const std::string& asset_name) const override;
36 
37   FML_DISALLOW_COPY_AND_ASSIGN(APKAssetProvider);
38 };
39 
40 }  // namespace flutter
41 
42 #endif  // FLUTTER_ASSETS_APK_ASSET_PROVIDER_H
43