You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
WebView: use Asset_read() instead of Asset_openFileDescriptor()
openFileDescriptor doesn't work for assets which are compressed inside the APK.
This commit is contained in:
30
src/api-impl-jni/AssetInputStream.c
Normal file
30
src/api-impl-jni/AssetInputStream.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <androidfw/androidfw_c_api.h>
|
||||
|
||||
#include "AssetInputStream.h"
|
||||
|
||||
static gssize asset_input_stream_read(GInputStream *gstream, void *buffer, gsize count, GCancellable *cancellable, GError **error) {
|
||||
return Asset_read(ATL_ASSET_INPUT_STREAM(gstream)->asset, buffer, count);
|
||||
}
|
||||
|
||||
static gboolean asset_input_stream_close(GInputStream *gstream, GCancellable *cancellable, GError **error) {
|
||||
AssetInputStream *stream = ATL_ASSET_INPUT_STREAM(gstream);
|
||||
Asset_delete(stream->asset);
|
||||
stream->asset = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void asset_input_stream_class_init(AssetInputStreamClass *class) {
|
||||
class->parent_class.read_fn = asset_input_stream_read;
|
||||
class->parent_class.close_fn = asset_input_stream_close;
|
||||
}
|
||||
|
||||
static void asset_input_stream_init(AssetInputStream *self) {
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE(AssetInputStream, asset_input_stream, G_TYPE_INPUT_STREAM)
|
||||
|
||||
GInputStream *asset_input_stream_new(struct Asset *asset) {
|
||||
AssetInputStream *stream = g_object_new(asset_input_stream_get_type(), NULL);
|
||||
stream->asset = asset;
|
||||
return &stream->parent_instance;
|
||||
}
|
||||
Reference in New Issue
Block a user