diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java index 67b6cbab44..347afa52f2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java @@ -9,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.util.Log; import io.flutter.plugin.common.*; +import io.flutter.view.FlutterMain; import io.flutter.view.FlutterNativeView; import io.flutter.view.FlutterView; import io.flutter.view.TextureRegistry; @@ -111,6 +112,16 @@ public class FlutterPluginRegistry return mFlutterView; } + @Override + public String lookupKeyForAsset(String asset) { + return FlutterMain.getLookupKeyForAsset(asset); + } + + @Override + public String lookupKeyForAsset(String asset, String packageName) { + return FlutterMain.getLookupKeyForAsset(asset, packageName); + } + @Override public Registrar publish(Object value) { mPluginMap.put(pluginKey, value); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java index b7eeba40a6..129274de1a 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java @@ -105,6 +105,29 @@ public interface PluginRegistry { */ FlutterView view(); + + /** + * Returns the file name for the given asset. + * The returned file name can be used to access the asset in the APK + * through the {@link AssetManager} API. + * + * @param asset the name of the asset. The name can be hierarchical + * @return the filename to be used with {@link AssetManager} + */ + String lookupKeyForAsset(String asset); + + /** + * Returns the file name for the given asset which originates from the + * specified packageName. The returned file name can be used to access + * the asset in the APK through the {@link AssetManager} API. + * + * @param asset the name of the asset. The name can be hierarchical + * @param packageName the name of the package from which the asset originates + * @return the file name to be used with {@link AssetManager} + */ + String lookupKeyForAsset(String asset, String packageName); + + /** * Publishes a value associated with the plugin being registered. * diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java index 2ab81444a1..d4a1c15de4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java @@ -73,7 +73,7 @@ public class FlutterMain { private static final String MANIFEST = "flutter.yaml"; private static String fromFlutterAssets(String filePath) { - return sFlutterAssetsDir + "/" + filePath; + return sFlutterAssetsDir + File.separator + filePath; } private static final Set SKY_RESOURCES = ImmutableSetBuilder.newInstance() @@ -308,4 +308,30 @@ public class FlutterMain { File appBundle = new File(dataDirectory, sFlutterAssetsDir); return appBundle.exists() ? appBundle.getPath() : null; } + + /** + * Returns the file name for the given asset. + * The returned file name can be used to access the asset in the APK + * through the {@link AssetManager} API. + * + * @param asset the name of the asset. The name can be hierarchical + * @return the filename to be used with {@link AssetManager} + */ + public static String getLookupKeyForAsset(String asset) { + return fromFlutterAssets(asset); + } + + /** + * Returns the file name for the given asset which originates from the + * specified packageName. The returned file name can be used to access + * the asset in the APK through the {@link AssetManager} API. + * + * @param asset the name of the asset. The name can be hierarchical + * @param packageName the name of the package from which the asset originates + * @return the file name to be used with {@link AssetManager} + */ + public static String getLookupKeyForAsset(String asset, String packageName) { + return getLookupKeyForAsset( + "packages" + File.separator + packageName + File.separator + asset); + } } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 12d1bf2907..e875f00073 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -254,6 +254,14 @@ public class FlutterView extends SurfaceView return mNativeView.getPluginRegistry(); } + public String getLookupKeyForAsset(String asset) { + return FlutterMain.getLookupKeyForAsset(asset); + } + + public String getLookupKeyForAsset(String asset, String packageName) { + return FlutterMain.getLookupKeyForAsset(asset, packageName); + } + public void addActivityLifecycleListener(ActivityLifecycleListener listener) { mActivityLifecycleListeners.add(listener); }