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:
Julian Winkler
2024-10-04 17:59:47 +02:00
parent 0627ae7e54
commit 21a75d7ff0
4 changed files with 45 additions and 7 deletions

View 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;
}